Skip to content

Commit

Permalink
cosolidate shared logic
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed May 5, 2024
1 parent 3c9ebdf commit 3c2a847
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 70 deletions.

This file was deleted.

52 changes: 26 additions & 26 deletions src/container_apps/Jordnaer.Chat/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,51 @@
using Serilog;

Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
.WriteTo.Console()
.CreateBootstrapLogger();

try
{
var builder = WebApplication.CreateBuilder(args);
var builder = WebApplication.CreateBuilder(args);

builder.AddAzureAppConfiguration();
builder.AddAzureAppConfiguration();

builder.AddSerilog();
builder.AddSerilog();

builder.AddDatabase();
builder.AddDatabase();

builder.AddMassTransit();
builder.AddMassTransit();

var app = builder.Build();
var app = builder.Build();

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

app.UseSerilog();
app.UseSerilog();

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

app.UseAzureAppConfiguration();
app.UseAzureAppConfiguration();

app.MapHealthChecks("/health").AllowAnonymous();
app.MapHealthChecks("/health").AllowAnonymous();

app.Run();
app.Run();
}
catch (Exception exception)
{
Log.Fatal(exception, "An unhandled exception occurred during application startup.");
Log.Fatal(exception, "An unhandled exception occurred during application startup.");
}
finally
{
Log.CloseAndFlush();
Log.CloseAndFlush();
}

public partial class Program { }
public partial class Program;
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.FeatureManagement;

namespace Jordnaer.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.FeatureManagement;

namespace Jordnaer.Shared.Infrastructure;

public static class AzureAppConfigurationExtensions
{
Expand All @@ -16,11 +19,10 @@ public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplication
builder.Services.AddAzureAppConfiguration();

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

builder.Configuration.AddAzureAppConfiguration(options =>
options.Connect(connectionString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.ElmahIo" Version="5.0.38" />
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.0" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.1.0" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions src/web/Jordnaer/Jordnaer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<PackageReference Include="Grafana.OpenTelemetry" Version="0.7.0-beta.4" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.2.1" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="8.0.4" />
Expand All @@ -25,7 +24,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.2.0" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.SendGrid" Version="8.0.1" />
<PackageReference Include="Bogus" Version="35.5.1" />
Expand Down

0 comments on commit 3c2a847

Please sign in to comment.