Initial ...
This commit is contained in:
+123
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xStorageService.DI;
|
||||
using xIds.Constants;
|
||||
using xIds.DI;
|
||||
using xIds.Interfaces;
|
||||
using xIds.Providers;
|
||||
|
||||
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();
|
||||
|
||||
//
|
||||
// Register App Configuration ...
|
||||
services.AddXAppConfiguration(Configuration);
|
||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
||||
|
||||
//
|
||||
// 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.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)
|
||||
{
|
||||
//
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
//
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
//
|
||||
// app.UseXRequestLogger();
|
||||
}
|
||||
|
||||
//
|
||||
// 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();
|
||||
|
||||
//
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
//
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapDefaultControllerRoute();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user