更改abp.vnext

This commit is contained in:
陈淳
2023-01-13 18:03:08 +08:00
parent 65377d9236
commit c905489ea5
22 changed files with 168 additions and 196 deletions

View File

@@ -1,70 +1,15 @@
using AspNetCore.Microsoft.AspNetCore.Builder;
using System.Reflection;
using Yi.Framework.Application;
using Yi.Framework.Application.Contracts;
using Yi.Framework.Autofac.Extensions;
using Yi.Framework.Core;
using Yi.Framework.Core.AutoMapper;
using Yi.Framework.Core.Extensions;
using Yi.Framework.Core.Sqlsugar;
using Yi.Framework.Core.Sqlsugar.Repository;
using Yi.Framework.Ddd;
using Yi.Framework.Ddd.Repository;
using Yi.Framework.Domain;
using Yi.Framework.Domain.Shared;
using Yi.Framework.Sqlsugar;
using Yi.Framework.Web;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseUrls(builder.Configuration.GetValue<string>("StartUrl"));
//添加模块
builder.UseYiModules(
typeof(YiFrameworkCoreModule).Assembly,
typeof(YiFrameworkCoreAutoMapperModule).Assembly,
typeof(YiFrameworkDddModule).Assembly,
typeof(YiFrameworkCoreSqlsugarModule).Assembly,
typeof(YiFrameworkSqlsugarModule).Assembly,
typeof(YiFrameworkDomainSharedModule).Assembly,
typeof(YiFrameworkDomainModule).Assembly,
typeof(YiFrameworkApplicationContractsModule).Assembly,
typeof(YiFrameworkApplicationModule).Assembly
);
//使用autofac
builder.Host.UseAutoFacServerProviderFactory();
//添加控制器与动态api
builder.Services.AddControllers();
builder.Services.AddAutoApiService(opt =>
{
//NETServiceTest所在程序集添加进动态api配置
opt.CreateConventional(typeof(YiFrameworkApplicationModule).Assembly);
});
//添加swagger
builder.Services.AddSwaggerServer<YiFrameworkApplicationModule>();
//添加配置文件
builder.Host.AddAppSettingsSecretsJson();
//添加模块
await builder.AddApplicationAsync<YiFrameworkWebModule>();
var app = builder.Build();
app.Services.GetRequiredService<IRepository<TestEntity>>();
//if (app.Environment.IsDevelopment())
{
app.UseSwaggerServer();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.UseRouting();
//使用动态api
app.UseAutoApiService();
app.MapControllers();
app.Run();
//使用模块化
await app.InitializeApplicationAsync();
await app.RunAsync();

View File

@@ -1,9 +0,0 @@
using Yi.Framework.Core.Attribute;
using Yi.Framework.Core.DependencyInjection;
namespace Yi.Framework.Web
{
public class TestEntity: ITransientDependency
{
}
}

View File

@@ -6,10 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="6.0.2" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="6.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Application\Yi.Framework.Application.csproj" />
<ProjectReference Include="..\Yi.Framework.AspNetCore\Yi.Framework.AspNetCore.csproj" />
<ProjectReference Include="..\Yi.Framework.Core.Autofac\Yi.Framework.Core.Autofac.csproj" />
<ProjectReference Include="..\Yi.Framework.Sqlsugar\Yi.Framework.Sqlsugar.csproj" />
</ItemGroup>

View File

@@ -1,17 +1,73 @@
using StartupModules;
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;
namespace Yi.Framework.Web
{
public class YiFrameworkWebModule : IStartupModule
[DependsOn(
typeof(AbpSwashbuckleModule),
typeof(YiFrameworkApplicationModule),
typeof(YiFrameworkSqlsugarModule),
typeof(AbpAspNetCoreMvcModule)
)]
public class YiFrameworkWebModule : AbpModule
{
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
public override void ConfigureServices(ServiceConfigurationContext context)
{
ConfigureAutoApiControllers();
ConfigureSwaggerServices(context.Services);
}
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
Console.WriteLine("还有谁");
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)
{
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);
}
}
}
);
}
}
}