Add project files.
This commit is contained in:
98
Core.Blueprint.Service.API/Program.cs
Normal file
98
Core.Blueprint.Service.API/Program.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
|
||||
using Azure.Identity;
|
||||
using Core.Blueprint.External.ClientConfiguration;
|
||||
using Core.Blueprint.Logging.Configuration;
|
||||
using Core.Blueprint.Service.API.Extensions;
|
||||
using Microsoft.AspNetCore.HttpLogging;
|
||||
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Configuration.AddAzureAppConfiguration(options =>
|
||||
{
|
||||
var endpoint = builder.Configuration.GetSection("Endpoints:AppConfigurationURI").Value;
|
||||
|
||||
if (string.IsNullOrEmpty(endpoint))
|
||||
throw new ArgumentException("The app configuration is missing");
|
||||
|
||||
options.Connect(new Uri(endpoint), new DefaultAzureCredential())
|
||||
.Select(KeyFilter.Any, "blueprint_service");
|
||||
|
||||
options.ConfigureKeyVault(keyVaultOptions =>
|
||||
{
|
||||
keyVaultOptions.SetCredential(new DefaultAzureCredential());
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddLogs(builder);
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Configuration
|
||||
.AddUserSecrets(Assembly.GetExecutingAssembly())
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
builder.Services.RegisterExternalLayer(builder.Configuration);
|
||||
builder.Services.AddServiceConfigurationLayer();
|
||||
builder.Services.AddResponseCompression();
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.AddMemoryCache();
|
||||
|
||||
builder.Host.ConfigureServices((context, services) =>
|
||||
{
|
||||
|
||||
services.AddLogging();
|
||||
services.AddControllers();
|
||||
services.AddProblemDetails();
|
||||
services.AddCors(options
|
||||
=> options.AddDefaultPolicy(policyBuilder
|
||||
=> policyBuilder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()));
|
||||
|
||||
builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options =>
|
||||
{
|
||||
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
});
|
||||
|
||||
services
|
||||
.AddEndpointsApiExplorer()
|
||||
.AddVersioning()
|
||||
.AddSwagger();
|
||||
|
||||
services.AddHealthChecks();
|
||||
services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All);
|
||||
|
||||
builder.Services.AddOutputCache(options =>
|
||||
{
|
||||
options.AddBasePolicy(builder =>
|
||||
builder.Expire(TimeSpan.FromSeconds(10)));
|
||||
options.AddPolicy("Expire20", builder =>
|
||||
builder.Expire(TimeSpan.FromSeconds(20)));
|
||||
options.AddPolicy("Expire30", builder =>
|
||||
builder.Expire(TimeSpan.FromSeconds(30)));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
app.MapControllers();
|
||||
app.UseCors();
|
||||
app.ConfigureSwagger();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseResponseCompression();
|
||||
app.UseOutputCache();
|
||||
app.UseResponseCaching();
|
||||
app.UseLogging(builder.Configuration);
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user