I have the code below for my Entity Framework context.
I am using the overloaded constructor to inject in an in memory database for testing. This works fine but when I use this in my MVC app I need to configure StructureMap for the DbConnection. I don't know how to do this
public class EfContext : DbContext
{
//This can be a full blown connection string or if it is just a single string like this it is defaulting to SQL Express
public EfContext() : base("SQLExpressPaxiumMusic")
{
}
public EfContext(DbConnection connection) : base(connection, true)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(new DbContextInitialiser());
}
public DbSet<User> Users { get; set; }
}
public static IContainer Initialize()
{
ObjectFactory.Configure(config =>
{
config.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
config.For<IWebAuthenticator>().Use<WebAuthenticator>();
config.For<EfContext>().Use<EfContext>();
config.For<IUserRepository>().Use<UserRepository>();
config.For<DbConnection>() ****What goes here**** ????
});
return ObjectFactory.Container;
}