0

I've just created a Web API application for .Net 4.5 to do some tests with Unity (IoC framework)*.

I've added Unity using Nuget:

Install-Package Unity

Then I've added Mvc5 support

Install-Package Unity.Mvc5

For the backend, I created a class project with an EF model in it, with minimal content. I registered it like this:

container.RegisterType<MyEntities>();

To do a basic process test, I added a repository and registered it like so:

container.RegisterType<IMyRepository, MyRepository>();

As far as I can tell everything is up and running, but when I execute, I get the notification that the Web API misses a reference to EF 5.

So I try add it like this:

Install-Package EntityFramework -Version 5.0.0

But then I get this error:

Unable to resolve dependencies. 'EntityFramework 5.0.0' is not compatible with 'Microsoft.AspNet.Identity.EntityFramework 1.0.0 constraint

The Microsoft.AspNet.Identity.EntityFramework reference was added during Web API project creation and it's (strangely) actually version 2.0!

I want to leave the project as is, because I think the above reference is for authentication? And I will be needing that at some point.

Any ideas on how to fix this?

  • I want to test registering an EF ObjectContext as a dependency, see my previous question.
Community
  • 1
  • 1
Spikee
  • 3,967
  • 7
  • 35
  • 68

1 Answers1

1

Asp Identity Entity Framework 2 has dependency to Entity Framework version 6.0.1 and above.

See documentation

Update your entity framework to latest version and then try your code.

Update-Package EntityFramework -version 6.1.3

Gedao
  • 1,025
  • 9
  • 13
  • That works, thanks! A bonus question if I may: I think Unity is set up correctly but I'm getting a 'no parameterless constructor' error for the homecontroller (which takes the IMyRepository as dependency). I added the container to the WebApiConfig, do I need to register it elsewhere as well (Owin perhaps)? – Spikee Nov 06 '15 at 08:43
  • See this link. I hope that it will help you. http://stackoverflow.com/questions/9527988/cannot-inject-dependencies-into-asp-net-web-api-controller-using-unity – Gedao Nov 06 '15 at 09:00