57 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
| using Autofac;
 | |
| 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 AutoMapper;
 | |
| using IRaCIS.Core.SCP.Service;
 | |
| 
 | |
| namespace IRaCIS.Core.SCP
 | |
| {
 | |
|     // 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<Repository>().As<IRepository>().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 + typeof(BaseService).Assembly.GetName().Name+".dll");
 | |
|             containerBuilder.RegisterAssemblyTypes(application).Where(t => t.FullName.Contains("Service"))
 | |
|                 .PropertiesAutowired().AsImplementedInterfaces();
 | |
| 
 | |
| 
 | |
|             //containerBuilder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
 | |
|             //containerBuilder.RegisterType<UserInfo>().As<IUserInfo>().InstancePerLifetimeScope();
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|         }
 | |
|     }
 | |
| } |