Abp 从空白WebApplication开始

开发环境:VS2022、.NET6

1、创建项目:BasicAspNetCoreApplication

Abp 从空白WebApplication开始_第1张图片

Abp 从空白WebApplication开始_第2张图片

Abp 从空白WebApplication开始_第3张图片

2、NuGet添加:Volo.Abp.AspNetCore.Mvc和Volo.Abp.Autofac,如下图所示:

Abp 从空白WebApplication开始_第4张图片

3、开始写代码,目录如下图所示:

Abp 从空白WebApplication开始_第5张图片

 3.1、添加启动模块AppModule.cs

using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;

namespace BasicAspNetCoreApplication
{
    [DependsOn(typeof(AbpAspNetCoreMvcModule))]
    [DependsOn(typeof(AbpAutofacModule))] //在模块上添加AbpAutofacModule
    public class AppModule:AbpModule
    {
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env=context.GetEnvironment();

            if (env.IsDevelopment())
            {
                app.UseExceptionHandler("/Error");

                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseConfiguredEndpoints();

            base.OnApplicationInitialization(context);
        }
    }
}

3.2、修改Program.cs

using BasicAspNetCoreApplication;

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseAutofac(); //添加AbpAutofacModule

builder.Services.ReplaceConfiguration(builder.Configuration);

builder.Services.AddApplication();

var app=builder.Build(); 

app.InitializeApplication();

app.Run();

你可能感兴趣的:(Abp,c#)