public IdempotencyModule( IServiceCollection services, string connectionString, IdempotencyMigrationsTableInfo migrationsTableInfo, IdempotencyTableInfo idempotencyTableInfo, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger <IdempotencyModule>(); services.AddDbContext <IdempotencyContext>( options => options .UseLoggerFactory(loggerFactory) .UseSqlServer( connectionString, x => x.MigrationsHistoryTable(migrationsTableInfo.TableName, migrationsTableInfo.Schema))); services.AddSingleton(new IdempotencyConnectionInfo(connectionString)); services.AddSingleton(migrationsTableInfo); services.AddSingleton(idempotencyTableInfo); logger.LogInformation( "Added {Context} to services:" + Environment.NewLine + "\tSchema: {Schema}" + Environment.NewLine + "\tTableName: {TableName}", nameof(IdempotencyContext), migrationsTableInfo.Schema, migrationsTableInfo.TableName); }
public IdempotencyContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder <IdempotencyContext>(); var tableInfo = new IdempotencyTableInfo("dbo"); optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFProviders.InMemory.IdempotencyContext;Trusted_Connection=True;"); return(new IdempotencyContext(optionsBuilder.Options, tableInfo)); }
public static void Run( string connectionString, string migrationsSchema, string migrationsTableName, IdempotencyTableInfo tableInfo, ILoggerFactory loggerFactory = null) { var migratorOptions = new DbContextOptionsBuilder <IdempotencyContext>() .UseSqlServer( connectionString, x => x.MigrationsHistoryTable(migrationsTableName, migrationsSchema)); if (loggerFactory != null) { migratorOptions = migratorOptions.UseLoggerFactory(loggerFactory); } TableInfo = tableInfo; using (var migrator = new IdempotencyContext(migratorOptions.Options, tableInfo)) migrator.Database.Migrate(); }
// This needs to be DbContextOptions<T> for Autofac! public IdempotencyContext( DbContextOptions <IdempotencyContext> options, IdempotencyTableInfo idempotencyTableInfo) : base(options) { _idempotencyTableInfo = idempotencyTableInfo; }