Skip to content

Commit

Permalink
Use in-box API for adding config sources
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Sep 25, 2020
1 parent a87afc0 commit 0049165
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Search.Documents" Version="11.1.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
Expand Down
25 changes: 8 additions & 17 deletions src/Dfc.CourseDirectory.Functions/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var environment = Environment.GetEnvironmentVariable("ENVIRONMENT") ?? "Production";

var configuration = GetConfiguration();
builder.Services.AddSingleton(configuration);
var configuration = builder.GetContext().Configuration;

builder.Services.AddSqlDataStore(configuration.GetConnectionString("DefaultConnection"));

Expand All @@ -46,22 +43,16 @@ public override void Configure(IFunctionsHostBuilder builder)

builder.Services.AddSingleton<Func<SearchClientSettings, SearchClient>>(settings =>
new SearchClient(new Uri(settings.Url), settings.IndexName, new AzureKeyCredential(settings.Key)));
}

IConfiguration GetConfiguration()
{
// Yuk - waiting on https://github.com/Azure/azure-webjobs-sdk/pull/2405 for a nicer way to do this
var sp = builder.Services.BuildServiceProvider();
var baseConfig = sp.GetRequiredService<IConfiguration>();

var configBuilder = new ConfigurationBuilder()
.AddConfiguration(baseConfig);

if (environment.Equals(Environments.Development, StringComparison.OrdinalIgnoreCase))
{
configBuilder.AddUserSecrets(typeof(Startup).Assembly);
}
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
var environment = Environment.GetEnvironmentVariable("ENVIRONMENT") ?? "Production";

return configBuilder.Build();
if (environment.Equals(Environments.Development, StringComparison.OrdinalIgnoreCase))
{
builder.ConfigurationBuilder.AddUserSecrets(typeof(Startup).Assembly);
}
}
}
Expand Down

0 comments on commit 0049165

Please sign in to comment.