Files
xSaherElmIds/Startup.cs
T
saherelm 8d392b3d84 - Program.cs: Arrow → معمولی، +Telemetry
- Startup.cs: isDevelopmentEnvironment var، +logging middleware
- xIds.csproj: +xLoggingService reference
2026-11-09 12:53:24 +03:30

144 lines
4.0 KiB
C#

using System;
using xIds.DI;
using System.IO;
using xIds.Constants;
using xIds.Providers;
using Newtonsoft.Json;
using xIds.Interfaces;
using System.Reflection;
using xLoggingService.DI;
using xStorageService.DI;
using xCommons.Extensions;
using xCommons.Configurations;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace xIds
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
//
// Register Validation Provider and all XCommons Module Services ...
services.AddXCommons(Configuration);
//
// Register App Configuration ...
services.AddXAppConfiguration(Configuration);
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
//
// Register Logging Service ...
services.AddXLoggingService(Configuration);
//
// Register XDataService Configuration ...
services.AddXDataServiceConfiguration(Configuration, ConnectionStringNames.IDENTITY_CONNECTION_NAME);
//
// Register Allowed Origins ...
services.AddXCors(appConfiguration.AllowedOrigins);
//
// Register Swagger ...
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
services.AddXSwagger(Configuration, xmlFilePath: xmlPath);
//
// Register IdentityServer to DI ...
// services.AddInMemoryXIdentityServer (Configuration);
services.AddEfSupportXIdentityServer(Configuration);
//
// Services Application and Api Key Management Services ...
services.AddXApplicationProvider(Configuration);
//
services.AddControllers()
.AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
//
// Register Authentication ...
services.AddXIdentityServerAuthentication(Configuration);
//
// Register Authorization ...
services.AddXAuthorization();
//
// Register Security Provider ...
services.AddSingleton<IXSecurityProvider, XSecurityProvider>();
}
public void Configure(
IApplicationBuilder app,
IWebHostEnvironment env,
ILogger<Startup> logger
)
{
//
var isDevelopmentEnvironment = env.IsDevelopment();
if (isDevelopmentEnvironment)
{
app.UseDeveloperExceptionPage();
}
//
// Use Swagger Middleware ...
app.UseXSwagger();
//
app.UseHttpsRedirection();
app.UseXForwardOptions();
//
// Using Cors ...
app.UseXCors();
//
// Force App to Use IdentityServer ...
app.UseXIdentityServer(logger);
//
// Force app to Use Storage Service ...
app.UseXStorageService();
//
app.UseRouting();
//
// Using Request Logging ...
if (!isDevelopmentEnvironment)
{
app.UseXRequestLogger();
}
//
app.UseAuthentication();
app.UseAuthorization();
//
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
}
}
}