Dependency injection can be configured when using the migration command of the entity framework?
The unit framework 7 supports dependency injection for the subdivision of DbContext This mechanism includes permission to configure data access outside of DbContext
. For example, to configure EF for a SQL server in the following, config.json
servicon services = ... var configuration = new configuration () . AddJsonFile ("config.json"); Services.AddEntityFramework (Configuration) AddSqlServer () .AddDbContext & lt; Billing DBcinTex & gt; (Config = & gt; config.UseSqlServer ());
However, the migration commands do not know to execute this code, so the ad-migration
will fail due to lack of provider or lack of connection string .
Migration can be done to work by overriding OnConfiguring
within the DbContext
subclass to specify the provider and configuration string, but this It happens when different configurations go elsewhere and eventually my migration command and both of my code becomes extremely complicated.
Note: My DbContext
remains in a separate assembly from the entry point which uses it and my solution is multiple start-up projects.
No comments:
Post a Comment