You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
245 lines
9.4 KiB
245 lines
9.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using IdentityModel;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Win_in.Sfs.Wms.Job.EntityFrameworkCore;
|
|
//using StackExchange.Redis;
|
|
using Microsoft.OpenApi.Models;
|
|
using Volo.Abp;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
|
|
using Volo.Abp.AspNetCore.Serilog;
|
|
using Volo.Abp.AuditLogging.EntityFrameworkCore;
|
|
using Volo.Abp.Autofac;
|
|
using Volo.Abp.Caching;
|
|
//using Volo.Abp.Caching.StackExchangeRedis;
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
using Volo.Abp.EntityFrameworkCore.SqlServer;
|
|
using Volo.Abp.Localization;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.MultiTenancy;
|
|
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
|
using Volo.Abp.Security.Claims;
|
|
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
|
using Volo.Abp.Swashbuckle;
|
|
using Volo.Abp.VirtualFileSystem;
|
|
using Volo.Abp.AspNetCore.Mvc;
|
|
using Win_in.Sfs.Wms.Job.Application;
|
|
using Win_in.Sfs.Wms.Job.Application.Contracts;
|
|
using Win_in.Sfs.Wms.Job.Domain;
|
|
using Win_in.Sfs.Wms.Job.Domain.Shared;
|
|
using Win_in.Sfs.Wms.Job.HttpApi;
|
|
|
|
namespace Win_in.Sfs.Wms.Job
|
|
{
|
|
[DependsOn(
|
|
typeof(JobApplicationModule),
|
|
typeof(JobEntityFrameworkCoreModule),
|
|
typeof(JobHttpApiModule),
|
|
typeof(AbpAspNetCoreMvcUiMultiTenancyModule),
|
|
typeof(AbpAutofacModule),
|
|
//typeof(AbpCachingStackExchangeRedisModule),
|
|
typeof(AbpEntityFrameworkCoreSqlServerModule),
|
|
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
|
|
typeof(AbpSettingManagementEntityFrameworkCoreModule),
|
|
typeof(AbpAspNetCoreSerilogModule),
|
|
typeof(AbpSwashbuckleModule)
|
|
)]
|
|
public class JobHttpApiHostModule : AbpModule
|
|
{
|
|
private bool _isMultiTenancy = true;
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
context.Services.AddAlwaysAllowAuthorization();
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
var configuration = context.Services.GetConfiguration();
|
|
_isMultiTenancy = Convert.ToBoolean(configuration["IsMultiTenancy"]);
|
|
ConfigureSwaggerServices(context.Services);
|
|
Configure<AbpDbContextOptions>(options =>
|
|
{
|
|
options.UseSqlServer();
|
|
});
|
|
|
|
Configure<AbpAspNetCoreMvcOptions>(options =>
|
|
{
|
|
options
|
|
.ConventionalControllers
|
|
.Create(typeof(JobApplicationModule).Assembly, opts
|
|
=>
|
|
{
|
|
opts.RootPath = "wms-job";
|
|
})
|
|
;
|
|
});
|
|
|
|
Configure<AbpMultiTenancyOptions>(options =>
|
|
{
|
|
options.IsEnabled = _isMultiTenancy;
|
|
});
|
|
|
|
if (hostingEnvironment.IsDevelopment())
|
|
{
|
|
Configure<AbpVirtualFileSystemOptions>(options =>
|
|
{
|
|
options.FileSets.ReplaceEmbeddedByPhysical<JobDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Win_in.Sfs.Wms.Job.Domain.Shared", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<JobDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Win_in.Sfs.Wms.Job.Domain", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<JobApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Win_in.Sfs.Wms.Job.Application.Contracts", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<JobApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Win_in.Sfs.Wms.Job.Application", Path.DirectorySeparatorChar)));
|
|
});
|
|
}
|
|
|
|
context.Services.AddAbpSwaggerGenWithOAuth(
|
|
configuration["AuthServer:Authority"],
|
|
new Dictionary<string, string>
|
|
{
|
|
{"Job", "Job API"}
|
|
},
|
|
options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo {Title = "Job API", Version = "v1"});
|
|
options.DocInclusionPredicate((docName, description) => true);
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
});
|
|
|
|
Configure<AbpLocalizationOptions>(options =>
|
|
{
|
|
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
|
|
});
|
|
|
|
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
.AddJwtBearer(options =>
|
|
{
|
|
options.Authority = configuration["AuthServer:Authority"];
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
|
|
options.Audience = "Auth";
|
|
});
|
|
|
|
Configure<AbpDistributedCacheOptions>(options =>
|
|
{
|
|
options.KeyPrefix = "Job:";
|
|
});
|
|
|
|
//if (!hostingEnvironment.IsDevelopment())
|
|
//{
|
|
// var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
|
|
// context.Services
|
|
// .AddDataProtection()
|
|
// .PersistKeysToStackExchangeRedis(redis, "Job-Protection-Keys");
|
|
//}
|
|
|
|
context.Services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(builder =>
|
|
{
|
|
builder
|
|
.WithOrigins(
|
|
configuration["App:CorsOrigins"]
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(o => o.RemovePostFix("/"))
|
|
.ToArray()
|
|
)
|
|
.WithAbpExposedHeaders()
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
var env = context.GetEnvironment();
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseErrorPage();
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseCorrelationId();
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseCors();
|
|
app.UseAuthentication();
|
|
if (_isMultiTenancy)
|
|
{
|
|
app.UseMultiTenancy();
|
|
}
|
|
app.UseAbpRequestLocalization();
|
|
app.UseAuthorization();
|
|
app.UseSwagger();
|
|
app.UseAbpSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API");
|
|
|
|
var configuration = context.GetConfiguration();
|
|
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
|
|
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
|
|
options.OAuthScopes("Job");
|
|
});
|
|
app.UseAuditing();
|
|
app.UseAbpSerilogEnrichers();
|
|
app.UseConfiguredEndpoints();
|
|
}
|
|
|
|
|
|
private void ConfigureSwaggerServices(IServiceCollection services)
|
|
{
|
|
|
|
services.AddSwaggerGen(
|
|
|
|
options =>
|
|
{
|
|
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
|
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
|
{
|
|
Name = "Authorization",
|
|
Scheme = "bearer",
|
|
Description = "Specify the authorization token.",
|
|
In = ParameterLocation.Header,
|
|
Type = SecuritySchemeType.Http,
|
|
});
|
|
|
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement()
|
|
{
|
|
{
|
|
new OpenApiSecurityScheme
|
|
{
|
|
Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "Bearer"}
|
|
},
|
|
new string[] { }
|
|
},
|
|
});
|
|
|
|
var basepath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
|
|
var xmlPath = Path.Combine(basepath, "Win_in.Sfs.Wms.Job.Application.xml");
|
|
options.IncludeXmlComments(xmlPath, false);
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|