예제 #1
0
        private static async Task ConfigureAndRunDatabaseCommandAsync(DatabaseOptions options)
        {
            var command = new ServiceCollection()
                          .ConfigureCommonServices(options)
                          .ConfigureDatabaseCommandServices(options)
                          .BuildServiceProvider()
                          .GetService <GenerateCdmFromDatabaseCommand>();

            await command.RunAsync(options);
        }
예제 #2
0
        public static IServiceCollection ConfigureDatabaseCommandServices(this IServiceCollection services, DatabaseOptions cliOptions)
        {
            if (cliOptions.SqlProvider == SqlProviderOption.SQLite)
            {
                services.AddSingleton <DbConnection>(new SqliteConnection(cliOptions.ConnectionString));
                services.AddScoped <IRelationalModelReader, SqliteRelationalModelReader>();
                services.AddScoped <ITypeValueAnnotationsReader, SqliteTypeValueAnnotationsReader>();
            }
            else if (cliOptions.SqlProvider == SqlProviderOption.SqlServer)
            {
                services.AddSingleton <DbConnection>(new SqlConnection(cliOptions.ConnectionString));
                services.AddScoped <IRelationalModelReader, SqlServerRelationalModelReader>();
                services.Configure <SqlRelationalModelReaderOptions>(c => c.SchemaFilterRegexPattern = cliOptions.SchemaFilterRegexPattern);
                services.AddScoped <ITypeValueAnnotationsReader, SqlServerTypeValueAnnotationsReader>();
            }

            services.AddScoped <GenerateCdmFromDatabaseCommand>();

            return(services);
        }