Exemplo n.º 1
0
        public MigrationRunner(
            [NotNull] IAssemblyCollection assemblies, [NotNull] IRunnerContext runnerContext,
            [NotNull] IMigrationProcessor processor, [CanBeNull] IVersionTableMetaData versionTableMetaData,
            [CanBeNull] IMigrationRunnerConventions migrationRunnerConventions, [CanBeNull] IConventionSet conventionSet,
            [CanBeNull] IMigrationScopeManager migrationScopeHandler = null)
        {
            _migrationAssemblies = assemblies;
            _logger           = new AnnouncerFluentMigratorLogger(runnerContext.Announcer);
            _stopWatch        = runnerContext.StopWatch;
            _processorOptions = new ProcessorOptions(runnerContext);

            Processor     = processor;
            RunnerContext = runnerContext;

            var migrationRunnerConventionsAccessor = new AssemblySourceMigrationRunnerConventionsAccessor(
                serviceProvider: null,
                new AssemblySource(() => assemblies));

            Conventions = migrationRunnerConventions ?? migrationRunnerConventionsAccessor.MigrationRunnerConventions;

            var convSet = conventionSet ?? new DefaultConventionSet(runnerContext);

            _migrationScopeManager = migrationScopeHandler ?? new MigrationScopeHandler(Processor);
            _migrationValidator    = new MigrationValidator(_logger, convSet);
            MigrationLoader        = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies,
                                                                           runnerContext.Namespace,
                                                                           runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader     = new ProfileLoader(runnerContext, this, Conventions);
            MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions);

            if (runnerContext.NoConnection)
            {
                _versionLoader = new Lazy <IVersionLoader>(
                    () => new ConnectionlessVersionLoader(
                        this,
                        _migrationAssemblies,
                        convSet,
                        Conventions,
                        runnerContext,
                        versionTableMetaData));
            }
            else
            {
                _versionLoader = new Lazy <IVersionLoader>(
                    () => new VersionLoader(this, _migrationAssemblies, convSet, Conventions, runnerContext, versionTableMetaData));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MigrationRunner"/> class.
        /// </summary>
        /// <param name="options">The migration runner options</param>
        /// <param name="processorOptions">The migration processor options</param>
        /// <param name="profileLoader">The profile loader</param>
        /// <param name="processorAccessor">The migration processor accessor</param>
        /// <param name="maintenanceLoader">The maintenance loader</param>
        /// <param name="migrationLoader">The migration loader</param>
        /// <param name="logger">The logger</param>
        /// <param name="stopWatch">The stopwatch</param>
        /// <param name="migrationRunnerConventionsAccessor">The accessor for migration runner conventions</param>
        /// <param name="assemblySource">The assemblies to scan for migrations, etc...</param>
        /// <param name="migrationValidator">The validator for migrations</param>
        /// <param name="serviceProvider">The service provider</param>
        /// <param name="migrationScopeHandler">THe migration scope handler</param>
        public MigrationRunner(
            [NotNull] IOptions <RunnerOptions> options,
            [NotNull] IOptionsSnapshot <ProcessorOptions> processorOptions,
            [NotNull] IProfileLoader profileLoader,
            [NotNull] IProcessorAccessor processorAccessor,
            [NotNull] IMaintenanceLoader maintenanceLoader,
            [NotNull] IMigrationInformationLoader migrationLoader,
            [NotNull] ILogger <MigrationRunner> logger,
            [NotNull] IStopWatch stopWatch,
            [NotNull] IMigrationRunnerConventionsAccessor migrationRunnerConventionsAccessor,
            [NotNull] IAssemblySource assemblySource,
            [NotNull] MigrationValidator migrationValidator,
            [NotNull] IServiceProvider serviceProvider,
            [CanBeNull] IMigrationScopeManager migrationScopeHandler)
        {
            Processor         = processorAccessor.Processor;
            Conventions       = migrationRunnerConventionsAccessor.MigrationRunnerConventions;
            ProfileLoader     = profileLoader;
            MaintenanceLoader = maintenanceLoader;
            MigrationLoader   = migrationLoader;

            _serviceProvider  = serviceProvider;
            _options          = options.Value;
            _logger           = logger;
            _stopWatch        = stopWatch;
            _processorOptions = processorOptions.Value;

            _migrationScopeManager = migrationScopeHandler ?? new MigrationScopeHandler(Processor, processorOptions.Value);
            _migrationValidator    = migrationValidator;
            _versionLoader         = new Lazy <IVersionLoader>(serviceProvider.GetRequiredService <IVersionLoader>);

#pragma warning disable 612
#pragma warning disable 618
            _migrationAssemblies = new AssemblyCollectionService(assemblySource);
#pragma warning restore 618
#pragma warning restore 612
        }