/// <summary> /// Initializes a new instance of the <see cref="SelectingProcessorAccessor"/> class. /// </summary> /// <param name="processors">The processors to select from</param> /// <param name="options">The options used to determine the processor to be returned</param> /// <param name="generatorSelectorOptions">The generator selector options</param> /// <param name="serviceProvider">The service provider</param> public SelectingProcessorAccessor( [NotNull, ItemNotNull] IEnumerable <IMigrationProcessor> processors, [NotNull] IOptions <SelectingProcessorAccessorOptions> options, [NotNull] IOptions <SelectingGeneratorAccessorOptions> generatorSelectorOptions, [NotNull] IServiceProvider serviceProvider) { var procs = processors.ToList(); var processorId = string.IsNullOrEmpty(options.Value.ProcessorId) ? generatorSelectorOptions.Value.GeneratorId : options.Value.ProcessorId; IMigrationProcessor foundProcessor; if (string.IsNullOrEmpty(processorId)) { // No generator selected if (procs.Count == 0) { throw new ProcessorFactoryNotFoundException("No migration processor registered."); } if (procs.Count > 1) { throw new ProcessorFactoryNotFoundException("More than one processor registered, but no processor id given. Specify the processor id by configuring SelectingProcessorAccessorOptions."); } foundProcessor = procs.Single(); //(Processor as ProcessorBase).Generator } else { // One of multiple generators foundProcessor = FindGenerator(procs, processorId); } // Special handling when no connection string could be found var connectionStringAccessor = serviceProvider.GetRequiredService <IConnectionStringAccessor>(); var connectionString = connectionStringAccessor.ConnectionString; if (string.IsNullOrEmpty(connectionString)) { if (foundProcessor is ProcessorBase processorBase) { var databaseIds = new List <string>() { processorBase.DatabaseType }; databaseIds.AddRange(processorBase.DatabaseTypeAliases); var processorOptions = serviceProvider.GetRequiredService <IOptions <ProcessorOptions> >(); foundProcessor = new ConnectionlessProcessor( new PassThroughGeneratorAccessor(processorBase.Generator), processorBase.Logger, processorOptions, databaseIds); } } Processor = foundProcessor; }
private IMigrationProcessor InitializeConnectionlessProcessor() { var options = new ProcessorOptions { PreviewOnly = RunnerContext.PreviewOnly, Timeout = RunnerContext.Timeout, ProviderSwitches = RunnerContext.ProviderSwitches }; var generator = new MigrationGeneratorFactory().GetGenerator(RunnerContext.Database); var processor = new ConnectionlessProcessor(generator, RunnerContext, options); return processor; }