參考 Abp vNext框架 從空項目開始 使用ASP.NET Core Web Application http://www.vnfan.com/helinbin/d/745b1e040c9b4f62.html rynowak的回答 https://github.com/aspnet/AspNet ...
參考
Abp vNext框架 從空項目開始 使用ASP.NET Core Web Application
http://www.vnfan.com/helinbin/d/745b1e040c9b4f62.html
rynowak的回答
https://github.com/aspnet/AspNetCore/issues/9542
Migrate from ASP.NET Core 2.2 to 3.0 -> Use MVC without Endpoint Routing
startup
ASP.NET Core 2.0 : 七.一張圖看透啟動背後的秘密
https://www.cnblogs.com/FlyLolo/p/ASPNETCore2_7.html
本人測試環境
vs2019
.net core3.0
庫版本
Volo.Abp.AspNetCore.Mvc 1.02
Volo.Abp.Autofac 1.02
步驟:
參考上文, 可建立一個helloworld工程.
說明:
vs2019建立工程可能有些許差別, 但原理基本一致.
遇到問題:
1.原文使用的庫在本人測試時已經有所升級(abp團隊已從.net core2.2升級為3.0), AppModule類中app.UseMvcWithDefaultRoute();報異常:
Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRounting = false' inside 'ConfigureServices'.
解決方法:
a.註釋該行代碼;
b.修改startup.cs
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddApplication<AppModule>(); //添加 services.AddMvc(option => option.EnableEndpointRouting = false); } public void Configure(IApplicationBuilder app) { app.InitializeApplication(); //添加 app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); } }
運行,解決.
其他:
隨著升級, autofac的使用也變的簡單, 引入庫之後, 直接在Program.cs的CreateHostBuilder方法中直接添加.UserAutofac()即可
public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); })
//添加 .UseAutofac(); }