31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
|
|
using Autofac;
|
|||
|
|
using Autofac.Extensions.DependencyInjection;
|
|||
|
|
using Microsoft.AspNetCore.Builder;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using QYZH.InteractiveMagazine.Models.Settings;
|
|||
|
|
using RabbitMQ.Client;
|
|||
|
|
using StackExchange.Redis;
|
|||
|
|
|
|||
|
|
namespace QYZH.InteractiveMagazine.Infrastructure.Autofacs
|
|||
|
|
{
|
|||
|
|
public static class AutofacExtension
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据程序集名称获取程序集
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="builder">Web应用程序构建器</param>
|
|||
|
|
public static void UseAutofac(this WebApplicationBuilder builder)
|
|||
|
|
{
|
|||
|
|
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
|||
|
|
.ConfigureContainer<ContainerBuilder>((c, containerBuilder) =>
|
|||
|
|
{
|
|||
|
|
var friendlyName = AppDomain.CurrentDomain.FriendlyName;
|
|||
|
|
var source = friendlyName.Split('.');
|
|||
|
|
var assemblyNames = string.Join(".", source.Take(source.Length - 1));
|
|||
|
|
containerBuilder.RegisterModule(new AutofacModuleRegister(assemblyNames));
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|