赞
踩
Abp官网,这里我们先初步整合WebApi模块化,待程序运行起来,后续文章我们再对Abp进行深入。
Volo,Abp:模块化必备
Volo.Abp.AspNetCore:装配Web项目DI容器注入必备
Volo.Autofac:Abp的DI容器
[DependsOn(typeof(AbpAspNetCoreModule))] public class AdminGatewayModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { // Add services to the container. context.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle context.Services.AddEndpointsApiExplorer(); context.Services.AddSwaggerGen(); } public override void OnApplicationInitialization(ApplicationInitializationContext context) { var env = context.GetEnvironment(); var app = context.GetApplicationBuilder(); if (env.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseRouting(); app.UseEndpoints(endpoint => { endpoint.MapControllers(); }); } }
public class Program { public async static Task Main(string[] args) { var builder = WebApplication.CreateBuilder(args); builder.Host.ConfigureAppConfiguration((context, builder) => { builder.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); }).UseAutofac(); await builder.AddApplicationAsync<IdentityServerHostModule>(); var app = builder.Build(); await app.InitializeApplicationAsync(); await app.RunAsync(); } }
注:这里有一点值得注意,在默认创建的WebApi项目中,路由映射是:app.MapControllers();,在Abp的Module中6.0版本不能直接引用,需要替换一下,否则会返回404。
替换并启动项目后,一切正常运行!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。