Reputation: 10509
I have an InDocDbContext: DbContext
and an InDocDbContextInitializer: DropCreateIfModelChangesInitializer
that "has been taught" to seed some initial data into the database.
I am trying my best to avoid putting an initialization code into my App_Start method in global.asax of my ASP.NET application.
I am using Ninject as an IOC container. Can I put Initialization logic inside NinjectModule or hide it in the context, so that I don't have to bring it to global.asax code?
Upvotes: 2
Views: 804
Reputation: 364399
You can add it to context's static constructor:
public InDocDbContext : DbContext
{
static InDocDbContext()
{
Database.SetInitializer<InDocDbContext>(new InDocDbContextInitializer());
}
}
If you are using EF 4.3 or newer you can also simply define the initializer in web.config file. See original 4.3 documentation or documentation for the current version.
Upvotes: 2