using System; using System.Reflection; using Abp; using Abp.Modules; using Castle.Facilities.TypedFactory; using Castle.Facilities.TypedFactory.Internal; using Castle.MicroKernel.Registration; using IwbZero.IocNamed; using WeEngine.Components.InterfaceFactory; using WeEngine.Configuration; using WeEngine.Enum; using WeEngine.Message; namespace WeEngine { [DependsOn(typeof(AbpKernelModule))] public class WeEngineCoreModule : AbpModule { public override void PreInitialize() { //删除Castle Windsor 中 DelegateFactory委托工厂 的组件 // Stop using AddFacility //IocManager.IocContainer.AddFacility(); // Initialise the TypedFactoryFacility manually, leaving out the DelegateFactory components. IocManager.IocContainer.Kernel.Register(new IRegistration[] { Component.For().NamedAutomatically(TypedFactoryFacility.InterceptorKey), // Disable DelegateFactory // Component.For().ImplementedBy().NamedAutomatically(TypedFactoryFacility.DelegateFactoryKey), Component.For().ImplementedBy().NamedAutomatically("Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector"), // Disable DelegateFactory // Component.For().ImplementedBy().NamedAutomatically(TypedFactoryFacility.DefaultDelegateSelectorKey) }); IocManager.IocContainer.Kernel.ComponentModelBuilder.AddContributor(new TypedFactoryCachingInspector()); IocManager.IocContainer.Register(Component.For().AsFactory( c => c.SelectedWith(new IocNamedTypeFactoryComponentSelector())), Component.For().AsFactory( c => c.SelectedWith(new IocNamedTypeFactoryComponentSelector()))); IocManager.IocContainer.Register(Classes.FromAssembly(typeof(IStatementRunner).Assembly) .IncludeNonPublicTypes() .BasedOn(typeof(IStatementRunner), typeof(IComponentRunner)) // 基类是 IStatementRunner || IComponentRunner 的 .WithService.Self() .WithService.DefaultInterfaces() .ConfigureIf( c => Attribute.IsDefined(c.Implementation, typeof(IocNamedAttribute)), // 使用 IocNamedAttribute的 c => { // 获取 ioc named 的名称 var iocName = c.Implementation.GetCustomAttribute().Name; c.Named(iocName); }) .LifestyleTransient()); Configuration.Settings.Providers.Add(); IocManager.Register(); } public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); } public override void PostInitialize() { MsgClientRegister(); } private void MsgClientRegister() { var MsgClient = IocManager.Resolve(); MsgClient.SendMessage( "WeEngine", $"客户端{MsgClient.ClientId}已注册"); MsgClient.SendMessage( "WeApp", $"客户端{MsgClient.ClientId}已注册"); } } }