Files
xSaherElmAiApi/Program.cs
T
2026-07-29 00:15:56 +03:30

259 lines
6.2 KiB
C#

// using xHttpService.DI;
// using xAiApi.Database;
// using xFileService.DI;
// using xDataService.DI;
// using xPushService.DI;
// using System.Text.Json;
// using System.Reflection;
// using xAiApi.Extensions;
// using xStringService.DI;
// using xStorageService.DI;
// using xCommons.Extensions;
// using xDataService.Models;
// using xIdentityService.DI;
// using xPushService.Helpers;
// using xCommons.Configurations;
// using System.Text.Json.Serialization;
// using IdentityModel.AspNetCore.OAuth2Introspection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace xAiApi
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
//
#region .net 10 Standard ...
// //
// // Create Application Builder ...
// 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(() =>
// {
// return new HttpClientHandler
// {
// ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
// };
// });
// //
// // 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;
// });
// //
// var lifeTime = ServiceLifetime.Scoped;
// var repositoryType = xDataService.Constants.XRepositoryType.EF;
// //
// // Register XIdentity Service ...
// builder.Services.AddXIdentityService(
// lifeTime: lifeTime,
// configuration: builder.Configuration
// );
// //
// // Storage Service ...
// builder.Services.AddXStorageService(builder.Configuration);
// //
// // Push Service ...
// builder.Services.AddXPushService(
// lifeTime: lifeTime,
// config: builder.Configuration
// );
// //
// // Preparing DataBases ...
// var databases = new List<XDatabaseDescriptor>
// {
// //
// // Introduce Ai Api Descriptor ...
// new XAiApiDatabaseDescriptor()
// };
// if (databases.HasChild())
// {
// //
// databases
// .ToList()
// .ForEach(database =>
// {
// //
// // Register DataBase ...
// builder.Services.AddXDatabase(
// lifeTime: lifeTime,
// descriptor: database,
// configuration: builder.Configuration
// );
// });
// }
// //
// // Register String Service ...
// builder.Services.AddXStringService<XAiApiDbContext>(
// lifeTime: lifeTime,
// repositoryType: repositoryType
// );
// //
// // Register File Service ...
// builder.Services.AddXFileService<XAiApiDbContext>(
// lifeTime: lifeTime,
// repositoryType: repositoryType
// );
// #endregion
// //
// // Creating Application ...
// var app = builder.Build();
// //
// #region Using Middlewares ...
// //
// // Configure the HTTP request pipeline.
// var isDevelopmentEnvironment = false;
// if (app.Environment.IsDevelopment())
// {
// isDevelopmentEnvironment = true;
// 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();
// });
// //
// // Use Storage Service ...
// app.UseXStorageService();
// //
// // Using DataBase ...
// if (databases.HasChild())
// {
// //
// databases
// .ToList()
// .ForEach(database =>
// {
// //
// app.UseXDatabase(
// descriptor: database,
// isDevelopmentEnvironment: isDevelopmentEnvironment
// );
// });
// }
// //
// // Use PushService ...
// var pushHelper = new XPushServiceHelper();
// app.UseXPushService(pushHelper);
// //
// // Using String Service ...
// app.UseXStringService(
// isDevelopmentEnvironment: isDevelopmentEnvironment
// );
// //
// // Using File Service ...
// app.UseXFileService(
// isDevelopmentEnvironment: isDevelopmentEnvironment
// );
// #endregion
// //
// // Runing Application ...
// app.Run();
#endregion