Abp vNext框架 从空项目开始 使用ASP.NET Core Web Application-笔记
参考
abp vnext框架 从空项目开始 使用asp.net core web application
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(); }