示例#1
0
        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);
        }
示例#2
0
        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));
        }
示例#3
0
        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();
        }
示例#4
0
 // This needs to be DbContextOptions<T> for Autofac!
 public IdempotencyContext(
     DbContextOptions <IdempotencyContext> options,
     IdempotencyTableInfo idempotencyTableInfo) : base(options)
 {
     _idempotencyTableInfo = idempotencyTableInfo;
 }