using Autofac;
namespace ERP.Framework.Extensions
{
///
/// Autofac扩展
///
public static class AutofacExtension
{
///
/// 初始化Autofac,注入Repository 和 Service
///
///
/// 程序集
public static void InitAutofac(this ContainerBuilder builder)
{
var assemblyList = AppDomain.CurrentDomain.GetAssemblies()
.Where(t => t.FullName != null && t.FullName.Contains("ERP"));
//根据名称约定(业务处理层以Service结尾,仓储层以Repository结尾),实现服务接口和服务实现的依赖
builder.RegisterAssemblyTypes(assemblyList.ToArray())
.Where(t => t.IsClass)
.Where(t => t.Name.EndsWith("Service") || t.Name.EndsWith("Repository"))
.AsSelf().AsImplementedInterfaces()
.InstancePerLifetimeScope();
}
}
}