using Autofac; using IRaCIS.Core.Application; using IRaCIS.Core.Application.BackGroundJob; using IRaCIS.Core.Infra.EFCore; using Microsoft.AspNetCore.Http; using Panda.DynamicWebApi; using System; using System.Linq; using System.Reflection; using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Application.Service; using IRaCIS.Application.Interfaces; using AutoMapper; namespace IRaCIS.Core.API { // ReSharper disable once IdentifierTypo public class AutofacModuleSetup : Autofac.Module { protected override void Load(ContainerBuilder containerBuilder) { #region byzhouhang 20210917 此处注册泛型仓储 可以减少Domain层 和Infra.EFcore 两层 空的仓储接口定义和 仓储文件定义 containerBuilder.RegisterGeneric(typeof(Repository<>)) .As(typeof(IRepository<>)).InstancePerLifetimeScope();//注册泛型仓储 containerBuilder.RegisterType().As().InstancePerLifetimeScope(); #endregion #region 指定控制器也由autofac 来进行实例获取 https://www.cnblogs.com/xwhqwer/p/15320838.html //获取所有控制器类型并使用属性注入 containerBuilder.RegisterAssemblyTypes(typeof(BaseService).Assembly) .Where(type => typeof(IDynamicWebApi).IsAssignableFrom(type)) .PropertiesAutowired(); #endregion Assembly application = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "IRaCIS.Core.Application.dll"); containerBuilder.RegisterAssemblyTypes(application).Where(t => t.FullName.Contains("Service")) .PropertiesAutowired().AsImplementedInterfaces(); //containerBuilder.RegisterType().As().SingleInstance(); //containerBuilder.RegisterType().As().InstancePerLifetimeScope(); //注册hangfire任务 依赖注入 containerBuilder.RegisterType().As().InstancePerDependency(); } } }