Cleanup and Backup Exists AiApi and Create a New .net 10 App and Configureit for using xDashboard ...
This commit is contained in:
+128
-16
@@ -1,20 +1,132 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Reflection;
|
||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||
using xAiApi.Extensions;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xHttpService.DI;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using xIdentityService.DI;
|
||||
|
||||
namespace xAiApi
|
||||
{
|
||||
public class Program
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
//
|
||||
#region Register services ...
|
||||
//
|
||||
// Register Validation Provider and all XCommons Module Services ...
|
||||
builder.Services.AddXCommons();
|
||||
|
||||
//
|
||||
// Register App Configuration ...
|
||||
builder.Services.AddXAppConfiguration(builder.Configuration);
|
||||
var appConfiguration = builder.Services.GetRegisteredService<XAppConfiguration>();
|
||||
|
||||
//
|
||||
// Register Allowed Origins ...
|
||||
builder.Services.AddXCors(appConfiguration.AllowedOrigins);
|
||||
|
||||
//
|
||||
// Register Swagger ...
|
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
builder.Services.AddXSwagger(builder.Configuration, xmlFilePath: xmlPath);
|
||||
|
||||
//
|
||||
// Register HttpService ...
|
||||
builder.Services.AddXHttpService(builder.Configuration);
|
||||
|
||||
//
|
||||
// Add Api V1 Versioning ...
|
||||
builder.Services.AddXApiV1Versioning();
|
||||
|
||||
//
|
||||
// OAuthIntrospectin Http Client Handler ...
|
||||
// this is for handling SSLErrors ...
|
||||
builder.Services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName)
|
||||
.ConfigurePrimaryHttpMessageHandler(() =>
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
return new HttpClientHandler
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
|
||||
};
|
||||
});
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
}
|
||||
//
|
||||
// Register Authorizations ...
|
||||
builder.Services.AddXAuthorization();
|
||||
|
||||
//
|
||||
// Mapping Controllers ...
|
||||
builder.Services.AddControllers()
|
||||
.AddJsonOptions(x =>
|
||||
{
|
||||
//
|
||||
// Optional but recommended for .NET 8+:
|
||||
// Allows reading properties case-insensitively (e.g., "myProp" matches "MyProp") ...
|
||||
x.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
||||
|
||||
//
|
||||
// This tells STJ to ignore circular references instead of throwing an exception ...
|
||||
x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
||||
|
||||
//
|
||||
// Camel Case Naming Policy ...
|
||||
x.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||
});
|
||||
|
||||
//
|
||||
// Register XIdentity Service ...
|
||||
builder.Services.AddXIdentityService(
|
||||
configuration: builder.Configuration,
|
||||
lifeTime: ServiceLifetime.Scoped
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
// Creating Application ...
|
||||
var app = builder.Build();
|
||||
|
||||
//
|
||||
#region Using Middlewares ...
|
||||
//
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
//
|
||||
// Use Swagger Middleware ...
|
||||
app.UseXSwagger();
|
||||
|
||||
//
|
||||
// Force Https Redirection ...
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
//
|
||||
// Using Cors ...
|
||||
app.UseXCors();
|
||||
|
||||
//
|
||||
// Using Routing ...
|
||||
app.UseRouting();
|
||||
|
||||
//
|
||||
// Use xIdentityService ...
|
||||
app.UseXIdentityService();
|
||||
|
||||
//
|
||||
// Use Authorization ...
|
||||
app.UseAuthorization();
|
||||
|
||||
//
|
||||
// Using Endpoints ...
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
_ = endpoints.MapControllers();
|
||||
});
|
||||
#endregion
|
||||
|
||||
//
|
||||
// Runing Application ...
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user