// We really need this code only locally, as the scripts are applied via SQL, so we pretty much us the local connection string? private static string ReadConnectionString() { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var currentDir = Directory.GetCurrentDirectory(); var configRoot = new ConfigurationBuilder() .SetBasePath(currentDir) .AddJsonFile("appsettings.json", false, false) .AddJsonFile($"appsettings.{environment}.json", true) .Build(); var section = configRoot.GetSection(AppSettings.SectionKey); var settings = new ServiceCollection() .Configure <AppSettings>(section) .AddSingleton(configRoot) .BuildServiceProvider() .GetService <IOptions <AppSettings> >(); var keyVaultPath = settings.Value.ConnectionStringKeyVaultPath; var readResult = KeyVaultProvider.TryProvidingSecret(keyVaultPath); if (!readResult.IsSuccess) { // This means we're on the build server, which actually doesn't need the connection string var tra = Environment.GetEnvironmentVariable("HelloWorld"); Console.WriteLine(tra); Debug.WriteLine(tra); return(tra); } return(readResult.Value); }
public DbContext Create() { var secretResult = KeyVaultProvider.TryProvidingSecret(_appSettings.Value.ConnectionStringKeyVaultPath); var options = new DbContextOptionsBuilder() .UseSqlServer(secretResult.Value) .ConfigureWarnings(f => f.Throw()) .Options; var result = new AppDbContext(options); return(result); }