Files
Yi.Admin/src/Yi.Framework/Yi.Framework.Web/YiFrameworkWebModule.cs

74 lines
2.3 KiB
C#
Raw Normal View History

2023-01-13 18:03:08 +08:00
using Microsoft.AspNetCore.Cors;
using Microsoft.OpenApi.Models;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Modularity;
using Volo.Abp.Swashbuckle;
using Yi.Framework.Application;
using Yi.Framework.Sqlsugar;
2023-01-11 11:10:59 +08:00
namespace Yi.Framework.Web
{
2023-01-13 18:03:08 +08:00
[DependsOn(
typeof(AbpSwashbuckleModule),
typeof(YiFrameworkApplicationModule),
typeof(YiFrameworkSqlsugarModule),
typeof(AbpAspNetCoreMvcModule)
)]
public class YiFrameworkWebModule : AbpModule
2023-01-11 11:10:59 +08:00
{
2023-01-13 18:03:08 +08:00
public override void ConfigureServices(ServiceConfigurationContext context)
2023-01-11 11:10:59 +08:00
{
2023-01-13 18:03:08 +08:00
ConfigureAutoApiControllers();
ConfigureSwaggerServices(context.Services);
2023-01-11 11:10:59 +08:00
}
2023-01-13 18:03:08 +08:00
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
app.UseStaticFiles();
app.UseRouting();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "YiFramework API");
});
app.UseConfiguredEndpoints();
}
private void ConfigureAutoApiControllers()
{
Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(YiFrameworkApplicationModule).Assembly);
});
}
private void ConfigureSwaggerServices(IServiceCollection services)
2023-01-11 11:10:59 +08:00
{
2023-01-13 18:03:08 +08:00
services.AddSwaggerGen(
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "YiFramework API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
var basePath = Path.GetDirectoryName(this.GetType().Assembly.Location);
if (basePath is not null)
{
foreach (var item in Directory.GetFiles(basePath, "*.xml"))
{
options.IncludeXmlComments(item, true);
}
}
}
);
2023-01-11 11:10:59 +08:00
}
}
}