HomeBlogGuideCatalogfavo
โ–ถ
+0
๐Ÿกฐ
ABP AbpAspNetCoreModule
ABP AbpAspNetCoreModule
2023/6/1
โžก๏ธ

AbpAspNetCoreModule

namespace Volo.Abp.AspNetCore;


AbpAspNetCoreModule ้‡Œ้…็ฝฎไบ† ABP ๅœจ ASP.NET CORE ไธŠๆไพ›็š„ไธ€ไบ›ๆœๅŠก

[DependsOn(
    typeof(AbpAuditingModule),
    typeof(AbpSecurityModule),
    typeof(AbpVirtualFileSystemModule),
    typeof(AbpUnitOfWorkModule),
    typeof(AbpHttpModule),
    typeof(AbpAuthorizationModule),
    typeof(AbpValidationModule),
    typeof(AbpExceptionHandlingModule)
    )]
public class AbpAspNetCoreModule : AbpModule
{
  public override void PreConfigureServices(ServiceConfigurationContext context)
  {
    var abpHostEnvironment = context.Services.GetSingletonInstance<IAbpHostEnvironment>();
    if (abpHostEnvironment.EnvironmentName.IsNullOrWhiteSpace())
    {
        abpHostEnvironment.EnvironmentName =
        context.Services.GetHostingEnvironment().EnvironmentName;
    }
  }

  public override void ConfigureServices(ServiceConfigurationContext context)
  {
      context.Services.AddAuthorization();

      Configure<AbpAuditingOptions>(options =>
      {
          options.Contributors.Add(new AspNetCoreAuditLogContributor());
      });

      Configure<StaticFileOptions>(options =>
      {
          options.ContentTypeProvider = context.Services.
          GetRequiredService<AbpFileExtensionContentTypeProvider>();
      });

      AddAspNetServices(context.Services);
      context.Services.AddObjectAccessor<IApplicationBuilder>();
      context.Services.AddAbpDynamicOptions<RequestLocalizationOptions,
        AbpRequestLocalizationOptionsManager>();
  }

  private static void AddAspNetServices(IServiceCollection services)
  {
      services.AddHttpContextAccessor();
  }

  public override void OnApplicationInitialization(ApplicationInitializationContext context)
  {
    var environment = context.GetEnvironmentOrNull();
    if (environment != null)
    {
        environment.WebRootFileProvider =
            new CompositeFileProvider(
                context.GetEnvironment().WebRootFileProvider,
                context.ServiceProvider.GetRequiredService<IWebContentFileProvider>()
            );
    }
  }
}
๐Ÿ‘๐ŸŽ‰๐ŸŽŠ