參考html
Abp vNext框架 從空項目開始 使用ASP.NET Core Web Applicationgit
http://www.vnfan.com/helinbin/d/745b1e040c9b4f62.htmlgithub
rynowak的回答web
https://github.com/aspnet/AspNetCore/issues/9542app
Migrate from ASP.NET Core 2.2 to 3.0 -> Use MVC without Endpoint Routing框架
startupvisual-studio
ASP.NET Core 2.0 : 七.一張圖看透啓動背後的祕密ui
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(); }