Skip to content

Commit 3c2a847

Browse files
committed
cosolidate shared logic
1 parent 3c9ebdf commit 3c2a847

File tree

5 files changed

+38
-70
lines changed

5 files changed

+38
-70
lines changed

src/container_apps/Jordnaer.Chat/AzureAppConfigurationExtensions.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/container_apps/Jordnaer.Chat/Program.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,51 @@
44
using Serilog;
55

66
Log.Logger = new LoggerConfiguration()
7-
.WriteTo.Console()
8-
.CreateBootstrapLogger();
7+
.WriteTo.Console()
8+
.CreateBootstrapLogger();
99

1010
try
1111
{
12-
var builder = WebApplication.CreateBuilder(args);
12+
var builder = WebApplication.CreateBuilder(args);
1313

14-
builder.AddAzureAppConfiguration();
14+
builder.AddAzureAppConfiguration();
1515

16-
builder.AddSerilog();
16+
builder.AddSerilog();
1717

18-
builder.AddDatabase();
18+
builder.AddDatabase();
1919

20-
builder.AddMassTransit();
20+
builder.AddMassTransit();
2121

22-
var app = builder.Build();
22+
var app = builder.Build();
2323

24-
app.UseForwardedHeaders(new ForwardedHeadersOptions
25-
{
26-
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
27-
});
24+
app.UseForwardedHeaders(new ForwardedHeadersOptions
25+
{
26+
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
27+
});
2828

29-
app.UseSerilog();
29+
app.UseSerilog();
3030

31-
// Configure the HTTP request pipeline.
32-
if (!app.Environment.IsDevelopment())
33-
{
34-
app.UseExceptionHandler("/Error");
35-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
36-
app.UseHsts();
37-
}
31+
// Configure the HTTP request pipeline.
32+
if (!app.Environment.IsDevelopment())
33+
{
34+
app.UseExceptionHandler("/Error");
35+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
36+
app.UseHsts();
37+
}
3838

39-
app.UseAzureAppConfiguration();
39+
app.UseAzureAppConfiguration();
4040

41-
app.MapHealthChecks("/health").AllowAnonymous();
41+
app.MapHealthChecks("/health").AllowAnonymous();
4242

43-
app.Run();
43+
app.Run();
4444
}
4545
catch (Exception exception)
4646
{
47-
Log.Fatal(exception, "An unhandled exception occurred during application startup.");
47+
Log.Fatal(exception, "An unhandled exception occurred during application startup.");
4848
}
4949
finally
5050
{
51-
Log.CloseAndFlush();
51+
Log.CloseAndFlush();
5252
}
5353

54-
public partial class Program { }
54+
public partial class Program;

src/web/Jordnaer/Extensions/AzureAppConfigurationExtensions.cs renamed to src/shared/Jordnaer.Shared.Infrastructure/AzureAppConfigurationExtensions.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using Microsoft.FeatureManagement;
2-
3-
namespace Jordnaer.Extensions;
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.FeatureManagement;
5+
6+
namespace Jordnaer.Shared.Infrastructure;
47

58
public static class AzureAppConfigurationExtensions
69
{
@@ -16,11 +19,10 @@ public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplication
1619
builder.Services.AddAzureAppConfiguration();
1720

1821
// This is set by Azure Service Connector
19-
var connectionString = builder.Configuration["AZURE_APPCONFIGURATION_ENDPOINT"];
20-
if (connectionString is null)
21-
{
22-
throw new InvalidOperationException("Failed to find connection string to Azure App Configuration. Keys checked: 'AZURE_APPCONFIGURATION_ENDPOINT'");
23-
}
22+
var connectionString = builder.Configuration["AZURE_APPCONFIGURATION_ENDPOINT"]
23+
?? throw new InvalidOperationException(
24+
"Failed to find connection string to Azure App Configuration. " +
25+
"Keys checked: 'AZURE_APPCONFIGURATION_ENDPOINT'");
2426

2527
builder.Configuration.AddAzureAppConfiguration(options =>
2628
options.Connect(connectionString)

src/shared/Jordnaer.Shared.Infrastructure/Jordnaer.Shared.Infrastructure.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
1010
<PackageReference Include="Serilog.Sinks.ElmahIo" Version="5.0.38" />
1111
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.0" />
12+
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.2.0" />
13+
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.1.0" />
1214
</ItemGroup>
1315
</Project>

src/web/Jordnaer/Jordnaer.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<PackageReference Include="Grafana.OpenTelemetry" Version="0.7.0-beta.4" />
1313
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
1414
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.2.1" />
15-
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.1.0" />
1615
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="8.0.4" />
1716
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.4" />
1817
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="8.0.4" />
@@ -25,7 +24,6 @@
2524
<PrivateAssets>all</PrivateAssets>
2625
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2726
</PackageReference>
28-
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.2.0" />
2927
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
3028
<PackageReference Include="AspNetCore.HealthChecks.SendGrid" Version="8.0.1" />
3129
<PackageReference Include="Bogus" Version="35.5.1" />

0 commit comments

Comments
 (0)