Esempio n. 1
0
        protected virtual void LoadMigrators()
        {
            Logger = new Logger(LoggerTextBox);

            IEnumerable <Type> migratorTypes =
                from a in AppDomain.CurrentDomain.GetAssemblies()
                from t in a.GetLoadableTypes()
                where t.IsClass && !t.IsAbstract && t.GetInterfaces().Contains(typeof(IMigrationConfiguration))
                select t;

            if (migratorTypes.Any())
            {
                foreach (Type type in migratorTypes)
                {
                    DbMigrationsConfiguration dbMigrationsConfiguration = (DbMigrationsConfiguration)Activator.CreateInstance(type);

                    IMigrationConfiguration migrationConfiguration = (IMigrationConfiguration)dbMigrationsConfiguration;
                    migrationConfiguration.Logger = Logger;
                    Logger.WriteLine("Found migration configuration for " + migrationConfiguration.Title);

                    Migrators.Add(migrationConfiguration.Title, dbMigrationsConfiguration);
                }
            }
            else
            {
                Logger.WriteLine("No migration configurations found");
            }
        }
Esempio n. 2
0
 private static IServiceProvider CreateServiceProvider(IMigrationConfiguration config) => new ServiceCollection()
 .AddFluentMigratorCore()
 .ConfigureRunner(runner => runner
                  .AddPostgres()
                  .WithGlobalConnectionString(config.PostgresConnection)
                  .ScanIn(typeof(MigrateCommand).Assembly).For.Migrations())
 .AddLogging(logger => logger.AddFluentMigratorConsole())
 .BuildServiceProvider(false);