| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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<TypedFactoryFacility>();
- // Initialise the TypedFactoryFacility manually, leaving out the DelegateFactory components.
- IocManager.IocContainer.Kernel.Register(new IRegistration[] {
- Component.For<TypedFactoryInterceptor>().NamedAutomatically(TypedFactoryFacility.InterceptorKey),
- // Disable DelegateFactory
- // Component.For<ILazyComponentLoader>().ImplementedBy<DelegateFactory>().NamedAutomatically(TypedFactoryFacility.DelegateFactoryKey),
- Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultTypedFactoryComponentSelector>().NamedAutomatically("Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector"),
- // Disable DelegateFactory
- // Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultDelegateComponentSelector>().NamedAutomatically(TypedFactoryFacility.DefaultDelegateSelectorKey)
- });
- IocManager.IocContainer.Kernel.ComponentModelBuilder.AddContributor(new TypedFactoryCachingInspector());
- IocManager.IocContainer.Register(Component.For<IStatementRunnerFactory>().AsFactory(
- c => c.SelectedWith(new IocNamedTypeFactoryComponentSelector())),
- Component.For<IComponentRunnerFactory>().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<IocNamedAttribute>().Name;
- c.Named(iocName);
- })
- .LifestyleTransient());
- Configuration.Settings.Providers.Add<IwbSettingProvider>();
- IocManager.Register<WeEngineMsgClientManager>();
- }
- public override void Initialize()
- {
- IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
-
- }
- public override void PostInitialize()
- {
- MsgClientRegister();
- }
- private void MsgClientRegister()
- {
- var MsgClient = IocManager.Resolve<WeEngineMsgClientManager>();
- MsgClient.SendMessage( "WeEngine", $"客户端{MsgClient.ClientId}已注册");
- MsgClient.SendMessage( "WeApp", $"客户端{MsgClient.ClientId}已注册");
- }
- }
- }
|