Tag Archives: Dependency Injection

Dependency Injection in ASP .NET 5 MVC 6

With ASP .NET 5 MVC 6 you do not have to rely on external Dependency Injection (DI) libraries any more. It comes with it’s on onboard DI. I will now demonstrate how to set up Dependency Injection for using Entity Framework 7 DbContexts within Controllers.

Register Service

For simplicity of this example I will not create a separate interface for my DbContext or implement a repository pattern for accessing the database. In bigger projects, I strongly recommend to do so, however. If you want to keep it simple like me you can directly register the DbContext for later on injection into Controllers in the class Startup.cs.

Continue reading

ASP .NET 5 with Entity Framework 7

Adding Entity Framework 7 Packages to ASP .NET Project

Older versions of the Entity Framework need a full .NET runtime in order to work. If at some point you want to use the new .NET 5 Core e.g. to run your application on Linux etc., you should use Entity Framework 7.

project.json:

A few comments regarding my project dependency setup. Of course, first of all you have to add the Entity Framework libraries as dependencies.

Continue reading