79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
using Fake.AspNetCore;
|
|
using Fake.AspNetCore.Auditing;
|
|
using Fake.AspNetCore.Mvc.Conventions;
|
|
using Fake.Autofac;
|
|
using Fake.Modularity;
|
|
using FluentValidation.AspNetCore;
|
|
using Hangfire;
|
|
using TrackCenter.Application;
|
|
using TrackCenter.Application.Hangfire;
|
|
using TrackCenter.Repository;
|
|
|
|
namespace TrackCenter.Api;
|
|
|
|
[DependsOn(typeof(FakeAutofacModule))]
|
|
[DependsOn(typeof(TrackCenterApplicationModule))]
|
|
[DependsOn(typeof(TrackCenterRepositoryModule))]
|
|
public class TrackCenterApiModule : FakeModule
|
|
{
|
|
private const string DefaultCorsPolicyName = "default";
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var services = context.Services;
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
services.Configure<ApplicationService2ControllerOptions>(options =>
|
|
{
|
|
options.ScanApplicationServices<TrackCenterApplicationModule>();
|
|
});
|
|
|
|
|
|
services.AddFakeExceptionFilter()
|
|
.AddFakeValidationActionFilter()
|
|
.AddFakeAspNetCoreAuditing()
|
|
.AddFakeUnitOfWorkActionFilter();
|
|
|
|
services.AddFakeSwaggerGen();
|
|
context.Services.AddFluentValidationAutoValidation().AddFluentValidationClientsideAdapters();
|
|
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
|
{
|
|
builder.WithOrigins(configuration.GetSection("App:CorsOrigins").Get<string[]>() ?? [])
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
}
|
|
|
|
public override void ConfigureApplication(ApplicationConfigureContext context)
|
|
{
|
|
var app = context.GetWebApplication();
|
|
var configuration = context.GetConfiguration();
|
|
|
|
app.MapControllers();
|
|
// Configure the HTTP request pipeline.
|
|
app.UseFakeSwagger();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseCors(DefaultCorsPolicyName);
|
|
|
|
// todo: 缺乏配置
|
|
app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
|
{
|
|
DisplayStorageConnectionString = false,
|
|
IgnoreAntiforgeryToken = true,
|
|
AppPath = configuration["Swagger:JsonUrlPrefix"]! + "/",
|
|
PrefixPath = System.Diagnostics.Debugger.IsAttached
|
|
? ""
|
|
: configuration["Swagger:JsonUrlPrefix"]!,
|
|
DashboardTitle = "轨迹预警任务",
|
|
Authorization = [new AnonymousHangfireAuthorizationFilter()]
|
|
});
|
|
}
|
|
}
|