64 lines
2.6 KiB
C#
64 lines
2.6 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using Autofac;
|
|
using Autofac.Extras.DynamicProxy;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.Services;
|
|
using IRaCIS.Core.API;
|
|
using IRaCIS.Core.API.Auth;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace IRaCIS.WX.CoreApi.Utility
|
|
{
|
|
// ReSharper disable once IdentifierTypo
|
|
public class CustomAutofacModule : Autofac.Module
|
|
{
|
|
protected override void Load(ContainerBuilder containerBuilder)
|
|
{
|
|
|
|
//containerBuilder.RegisterType<TokenService>().As<ITokenService>();
|
|
|
|
//containerBuilder.RegisterType<LogService>().As<ILogService>().SingleInstance();
|
|
|
|
//containerBuilder.RegisterType<DoctorService>().As<IDoctorService>().InstancePerLifetimeScope().EnableInterfaceInterceptors();
|
|
|
|
//Assembly domain = Assembly.Load("IRaCIS.Core.Domain");
|
|
//containerBuilder.RegisterAssemblyTypes(domain).AsImplementedInterfaces();
|
|
|
|
//Assembly domainShare = Assembly.Load("IRaCIS.Core.Domain.Share");
|
|
//containerBuilder.RegisterAssemblyTypes(domainShare).AsImplementedInterfaces();
|
|
|
|
//Assembly infrastructure = Assembly.Load("IRaCIS.Core.Infra.EFCore");
|
|
//containerBuilder.RegisterAssemblyTypes(infrastructure).AsImplementedInterfaces();
|
|
|
|
//Assembly application = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "IRaCIS.Core.Application.dll");
|
|
//containerBuilder.RegisterAssemblyTypes(application).AsImplementedInterfaces();
|
|
|
|
|
|
#region 指定控制器也由autofac 来进行实例获取
|
|
|
|
#region 老方式
|
|
//var assembly = this.GetType().GetTypeInfo().Assembly;
|
|
//var builder = new ContainerBuilder();
|
|
//var manager = new ApplicationPartManager();
|
|
//manager.ApplicationParts.Add(new AssemblyPart(assembly));
|
|
//manager.FeatureProviders.Add(new ControllerFeatureProvider());
|
|
//var feature = new ControllerFeature();
|
|
//manager.PopulateFeature(feature);
|
|
//builder.RegisterType<ApplicationPartManager>().AsSelf().SingleInstance();
|
|
//builder.RegisterTypes(feature.Controllers.Select(ti => ti.AsType()).ToArray()).PropertiesAutowired();
|
|
|
|
|
|
#endregion
|
|
|
|
//获取所有控制器类型并使用属性注入
|
|
//var controllerBaseType = typeof(ControllerBase);
|
|
//containerBuilder.RegisterAssemblyTypes(typeof(Program).Assembly)
|
|
// .Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType)
|
|
// .PropertiesAutowired();
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|
|
} |