参考

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

https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio

startup

https://github.com/aspnet/AspNetCore/blob/master/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs#L105

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(); }

 

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐