MigrationsExtensionsDbContextDesignTimeFactory - denmitchell/EDennis.AspNetCore.Base GitHub Wiki
EDennis.AspNetCore.Base provides an abstract implementation of IDesignTimeDbContextFactory in order to simplify/standardize migration-specific configuration aspects of your DbContext (e.g., connection string) and to allow your DbContext class to have just one constructor that takes DbContextOptions<YourDbContextClass> as a parameter.
The base class, MigrationsExtensionsDbContextDesignTimeFactory, makes two assumptions:
- Your DbContext class has a single constructor that takes
DbContextOptions<YourDbContextClass>as a parameter. - You have configured your connection string in either appsettings.json or appsettings.Development.json with the following key:
ConnectionStrings:YourDbContextClass(where YourDbContextClass is the name of your DbContext class).
When these assumptions hold, you can create a trivial subclass of MigrationsExtensionsDbContextDesignTimeFactory as such:
public class YourDbContextClassDesignTimeFactory :
MigrationsExtensionsDbContextDesignTimeFactory<YourDbContextClass> { }For convenience, you may wish to include the above class in the file that contains your DbContext class.