|
|
@@ -0,0 +1,210 @@
|
|
|
+using Procurement.EntityFrameworkCore;
|
|
|
+using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
+using Microsoft.AspNetCore.Builder;
|
|
|
+using Microsoft.AspNetCore.Cors;
|
|
|
+using Microsoft.AspNetCore.DataProtection;
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.DependencyInjection;
|
|
|
+using Microsoft.Extensions.Hosting;
|
|
|
+using Microsoft.OpenApi.Models;
|
|
|
+using StackExchange.Redis;
|
|
|
+using System;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using Volo.Abp;
|
|
|
+using Volo.Abp.AspNetCore.MultiTenancy;
|
|
|
+using Volo.Abp.AspNetCore.Mvc;
|
|
|
+using Volo.Abp.AspNetCore.Serilog;
|
|
|
+using Volo.Abp.Autofac;
|
|
|
+using Volo.Abp.Caching;
|
|
|
+using Volo.Abp.Data;
|
|
|
+using Volo.Abp.EntityFrameworkCore.MySQL;
|
|
|
+using Volo.Abp.Localization;
|
|
|
+using Volo.Abp.Modularity;
|
|
|
+using Volo.Abp.MultiTenancy;
|
|
|
+using Volo.Abp.Threading;
|
|
|
+using Volo.Abp.VirtualFileSystem;
|
|
|
+
|
|
|
+namespace Procurement
|
|
|
+{
|
|
|
+ [DependsOn(
|
|
|
+ typeof(AbpAutofacModule),
|
|
|
+ typeof(AbpEntityFrameworkCoreMySQLModule),
|
|
|
+ typeof(DigitalManufacturingApplicationModule),
|
|
|
+ typeof(DigitalManufacturingEntityFrameworkCoreModule),
|
|
|
+ typeof(AbpAspNetCoreMultiTenancyModule),
|
|
|
+ typeof(AbpAspNetCoreSerilogModule),
|
|
|
+ typeof(AbpAspNetCoreMvcModule)
|
|
|
+ )]
|
|
|
+ public class ProcurementHostModule : AbpModule
|
|
|
+ {
|
|
|
+ private const string DefaultCorsPolicyName = "Default";
|
|
|
+
|
|
|
+ public override void ConfigureServices(ServiceConfigurationContext context)
|
|
|
+ {
|
|
|
+ var configuration = context.Services.GetConfiguration();
|
|
|
+ var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
|
+
|
|
|
+ ConfigureConventionalControllers();
|
|
|
+ ConfigureMultiTenancy();
|
|
|
+ ConfigureAuthentication(context, configuration);
|
|
|
+ ConfigureLocalization();
|
|
|
+ ConfigureCache(configuration);
|
|
|
+ ConfigureVirtualFileSystem(context);
|
|
|
+ ConfigureCors(context, configuration);
|
|
|
+ //ConfigureRedis(context, configuration, hostingEnvironment);
|
|
|
+ ConfigureSwaggerServices(context);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureConventionalControllers()
|
|
|
+ {
|
|
|
+ Configure<AbpAspNetCoreMvcOptions>(options =>
|
|
|
+ {
|
|
|
+ options.ConventionalControllers.Create(typeof(DigitalManufacturingApplicationModule).Assembly, opts =>
|
|
|
+ {
|
|
|
+ opts.RootPath = "digitalmanufacturing";
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureMultiTenancy()
|
|
|
+ {
|
|
|
+ Configure<AbpMultiTenancyOptions>(options =>
|
|
|
+ {
|
|
|
+ options.IsEnabled = true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureCache(IConfiguration configuration)
|
|
|
+ {
|
|
|
+ Configure<AbpDistributedCacheOptions>(options =>
|
|
|
+ {
|
|
|
+ options.KeyPrefix = "DigitalManufacturing:";
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
|
|
|
+ {
|
|
|
+ context.Services.AddCors(options =>
|
|
|
+ {
|
|
|
+ options.AddPolicy(DefaultCorsPolicyName, builder =>
|
|
|
+ {
|
|
|
+ builder
|
|
|
+ .WithOrigins(
|
|
|
+ configuration["App:CorsOrigins"]
|
|
|
+ .Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
|
+ .Select(o => o.RemovePostFix("/"))
|
|
|
+ .ToArray()
|
|
|
+ )
|
|
|
+ .WithAbpExposedHeaders()
|
|
|
+ .SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
|
+ .AllowAnyHeader()
|
|
|
+ .AllowAnyMethod()
|
|
|
+ .AllowCredentials();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
|
|
|
+ {
|
|
|
+ var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
|
+
|
|
|
+ if (hostingEnvironment.IsDevelopment())
|
|
|
+ {
|
|
|
+ Configure<AbpVirtualFileSystemOptions>(options =>
|
|
|
+ {
|
|
|
+ options.FileSets.ReplaceEmbeddedByPhysical<DigitalManufacturingDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}DigitalManufacturing.Domain"));
|
|
|
+ options.FileSets.ReplaceEmbeddedByPhysical<DigitalManufacturingApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}DigitalManufacturing.Application.Contracts"));
|
|
|
+ options.FileSets.ReplaceEmbeddedByPhysical<DigitalManufacturingApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}DigitalManufacturing.Application"));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
|
|
|
+ {
|
|
|
+ context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
|
+ .AddJwtBearer(options =>
|
|
|
+ {
|
|
|
+ options.Authority = configuration["AuthServer:Authority"];
|
|
|
+ options.RequireHttpsMetadata = false;
|
|
|
+ options.Audience = "BusinessService";
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void ConfigureSwaggerServices(ServiceConfigurationContext context)
|
|
|
+ {
|
|
|
+ context.Services.AddSwaggerGen(
|
|
|
+ options =>
|
|
|
+ {
|
|
|
+ options.SwaggerDoc("v1", new OpenApiInfo { Title = "DigitalManufacturing Service API", Version = "v1" });
|
|
|
+ options.DocInclusionPredicate((docName, description) => true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureLocalization()
|
|
|
+ {
|
|
|
+ Configure<AbpLocalizationOptions>(options =>
|
|
|
+ {
|
|
|
+ options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
|
|
|
+ options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
|
|
+ options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
|
|
|
+ options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
|
|
|
+ options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
|
|
|
+ options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ConfigureRedis(
|
|
|
+ ServiceConfigurationContext context,
|
|
|
+ IConfiguration configuration,
|
|
|
+ IWebHostEnvironment hostingEnvironment)
|
|
|
+ {
|
|
|
+ context.Services.AddStackExchangeRedisCache(options =>
|
|
|
+ {
|
|
|
+ options.Configuration = configuration["Redis:Configuration"];
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!hostingEnvironment.IsDevelopment())
|
|
|
+ {
|
|
|
+ var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
|
|
|
+ context.Services
|
|
|
+ .AddDataProtection()
|
|
|
+ .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
|
+ {
|
|
|
+ var app = context.GetApplicationBuilder();
|
|
|
+
|
|
|
+ app.UseCorrelationId();
|
|
|
+ app.UseStaticFiles();
|
|
|
+ app.UseRouting();
|
|
|
+ app.UseCors(DefaultCorsPolicyName);
|
|
|
+ app.UseAuthentication();
|
|
|
+ app.UseAbpClaimsMap();
|
|
|
+ app.UseMultiTenancy();
|
|
|
+
|
|
|
+ app.UseAbpRequestLocalization();
|
|
|
+ app.UseSwagger();
|
|
|
+ app.UseSwaggerUI(options =>
|
|
|
+ {
|
|
|
+ options.SwaggerEndpoint("/swagger/v1/swagger.json", "DigitalManufacturing Service API");
|
|
|
+ });
|
|
|
+ app.UseAuditing();
|
|
|
+ app.UseAbpSerilogEnrichers();
|
|
|
+ app.UseConfiguredEndpoints();
|
|
|
+
|
|
|
+ AsyncHelper.RunSync(async () =>
|
|
|
+ {
|
|
|
+ using (var scope = context.ServiceProvider.CreateScope())
|
|
|
+ {
|
|
|
+ await scope.ServiceProvider
|
|
|
+ .GetRequiredService<IDataSeeder>()
|
|
|
+ .SeedAsync();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|