Search code examples
asp.net-mvcdependency-injectionentity-framework-4.1separation-of-concerns

Decoupling an ASP.NET MVC application from Entity Framework


If I have this project structure

  • Foo.Data
    • reference EntityFramework
  • Foo.Business
    • reference Foo.Data
  • Foo.Web
    • reference Foo.Business

Isn't that supposed to allow me to prevent adding a reference to EntityFramework from Foo.Web?

How can I call System.Data.Entity.Database.SetInitializer() from my global.asax.cs without adding the EntityFramework reference?


Solution

  • What you can do is create a InitializeDatabase() function in your Foo.Business project which in-turn calls System.Data.Entity.Database.SetInitializer(). You can then call InitializeDatabase() from your Foo.Web project which already has a reference to Foo.Business