Following on from How do I inject a connection string into an instance of IDbContextFactory? and several basically similar questions, I am wondering what the point of IDbContextFactory<T>
is for Entity Framework migrations.
According to MSDN IDbContextFactory<T>
is all about design-time support, which doesn't really seem particularly relevant to Code-First Migrations.
Any factory classes implemented must implement a default constructor themselves (which is the one that EF/ Migrations uses) and must implement the generic T Create()
method. This just seems a repeated abstraction, I can't see it adds anything (maybe this is necessary for design-time approaches.)
This means there is no way of doing any constructor-injection, which means I can't really use this in reality, as various parameters (including, but not limited to the nameOrConnectionString
aren't known until runtime). See also Entity Framework 4.3.1 migrations always invokes default constructor and ignores connectionstring and Manually Provide DbContext to DbMigrator. A bunch of hacks.
With EF in particular, IoC
at all and Dependency Injection
specifically always seems to be an after-thought, if there at all.