protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { V_0 = MixService.GetConnectionString("MixCmsConnection"); if (!string.IsNullOrEmpty(V_0)) { switch (Enum.Parse <MixEnums.DatabaseProvider>(MixService.GetConfig <string>("DatabaseProvider"))) { case 0: { dummyVar0 = SqlServerDbContextOptionsExtensions.UseSqlServer(optionsBuilder, V_0, null); return; } case 1: { dummyVar1 = MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, V_0, null); return; } case 2: { dummyVar2 = NpgsqlDbContextOptionsExtensions.UseNpgsql(optionsBuilder, V_0, null); break; } default: { return; } } } return; }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { var dbhost = Environment.GetEnvironmentVariable("DBHOST"); if (string.IsNullOrEmpty(dbhost)) { dbhost = "localhost"; } var dbname = Environment.GetEnvironmentVariable("DBNAME"); if (string.IsNullOrEmpty(dbname)) { dbname = "socomap"; } var dbuser = Environment.GetEnvironmentVariable("DBUSER"); if (string.IsNullOrEmpty(dbuser)) { dbuser = "******"; } var dbpass = Environment.GetEnvironmentVariable("DBPASS"); if (string.IsNullOrEmpty(dbpass)) { dbpass = "******"; } var connection = $"Host={dbhost}; Database={dbname}; Username={dbuser}; Password={dbpass};"; services.AddDbContext <TransmissionContext>(options => options.UseNpgsql(connection, b => b.MigrationsAssembly("Socomap"))); { var optionsBuilder = NpgsqlDbContextOptionsExtensions.UseNpgsql(new DbContextOptionsBuilder <TransmissionContext>(), connection, b => b.MigrationsAssembly("Socomap")); var transmissionContext = new TransmissionContext(optionsBuilder.Options); var pendingMigrations = transmissionContext.Database.GetPendingMigrations(); if (pendingMigrations != null && pendingMigrations.Any()) { transmissionContext.Database.Migrate(); } } services.AddTransient <IInboxAdapter, InboxAdapter>((IServiceProvider serviceProvider) => { var optionsBuilder = NpgsqlDbContextOptionsExtensions.UseNpgsql(new DbContextOptionsBuilder <TransmissionContext>(), connection, b => b.MigrationsAssembly("Socomap")); var transmissionContext = new TransmissionContext(optionsBuilder.Options); var inboxes = new Inboxes(transmissionContext); var transmissions = new Transmissions(transmissionContext, inboxes); return(new InboxAdapter(inboxes, transmissions)); }); services.AddTransient <ITransferAdapter, TransferAdapter>((IServiceProvider serviceProvider) => { var optionsBuilder = NpgsqlDbContextOptionsExtensions.UseNpgsql(new DbContextOptionsBuilder <TransmissionContext>(), connection, b => b.MigrationsAssembly("Socomap")); var transmissionContext = new TransmissionContext(optionsBuilder.Options); var inboxes = new Inboxes(transmissionContext); var transmissions = new Transmissions(transmissionContext, inboxes); return(new TransferAdapter(inboxes, transmissions)); } ); // Setup the database. // Add framework services. services .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); opts.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true }); }); services .AddSwaggerGen(c => { c.SwaggerDoc("0.0.1", new Info { Version = "0.0.1", Title = "SOCOMAP", Description = "SOCOMAP (ASP.NET Core 2.2)", Contact = new Contact() { Name = "Infotech GmbH", Url = "http://www.infotech.de", Email = "*****@*****.**" }, TermsOfService = "http://www.infotech.de" }); c.CustomSchemaIds(type => type.FriendlyId(true)); c.DescribeAllEnumsAsStrings(); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); // Sets the basePath property in the Swagger document generated c.DocumentFilter <BasePathFilter>("/v1"); // Include DataAnnotation attributes on Controller Action parameters as Swagger validation rules (e.g required, pattern, ..) // Use [ValidateModelState] on Actions to actually validate it in C# as well! c.OperationFilter <GeneratePathParamsValidationFilter>(); }); }
public static DbContextOptions <TContext> GetDbContextOptions <TContext>(string connectionString) where TContext : DbContext { return(NpgsqlDbContextOptionsExtensions.UseNpgsql(new DbContextOptionsBuilder <TContext>(), connectionString).Options); }