WeEngineCoreModule.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Reflection;
  3. using Abp;
  4. using Abp.Modules;
  5. using Castle.Facilities.TypedFactory;
  6. using Castle.Facilities.TypedFactory.Internal;
  7. using Castle.MicroKernel.Registration;
  8. using IwbZero.IocNamed;
  9. using WeEngine.Components.InterfaceFactory;
  10. using WeEngine.Configuration;
  11. using WeEngine.Enum;
  12. using WeEngine.Message;
  13. namespace WeEngine
  14. {
  15. [DependsOn(typeof(AbpKernelModule))]
  16. public class WeEngineCoreModule : AbpModule
  17. {
  18. public override void PreInitialize()
  19. {
  20. //删除Castle Windsor 中 DelegateFactory委托工厂 的组件
  21. // Stop using AddFacility
  22. //IocManager.IocContainer.AddFacility<TypedFactoryFacility>();
  23. // Initialise the TypedFactoryFacility manually, leaving out the DelegateFactory components.
  24. IocManager.IocContainer.Kernel.Register(new IRegistration[] {
  25. Component.For<TypedFactoryInterceptor>().NamedAutomatically(TypedFactoryFacility.InterceptorKey),
  26. // Disable DelegateFactory
  27. // Component.For<ILazyComponentLoader>().ImplementedBy<DelegateFactory>().NamedAutomatically(TypedFactoryFacility.DelegateFactoryKey),
  28. Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultTypedFactoryComponentSelector>().NamedAutomatically("Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector"),
  29. // Disable DelegateFactory
  30. // Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultDelegateComponentSelector>().NamedAutomatically(TypedFactoryFacility.DefaultDelegateSelectorKey)
  31. });
  32. IocManager.IocContainer.Kernel.ComponentModelBuilder.AddContributor(new TypedFactoryCachingInspector());
  33. IocManager.IocContainer.Register(Component.For<IStatementRunnerFactory>().AsFactory(
  34. c => c.SelectedWith(new IocNamedTypeFactoryComponentSelector())),
  35. Component.For<IComponentRunnerFactory>().AsFactory(
  36. c => c.SelectedWith(new IocNamedTypeFactoryComponentSelector())));
  37. IocManager.IocContainer.Register(Classes.FromAssembly(typeof(IStatementRunner).Assembly)
  38. .IncludeNonPublicTypes()
  39. .BasedOn(typeof(IStatementRunner), typeof(IComponentRunner)) // 基类是 IStatementRunner || IComponentRunner 的
  40. .WithService.Self()
  41. .WithService.DefaultInterfaces()
  42. .ConfigureIf(
  43. c => Attribute.IsDefined(c.Implementation, typeof(IocNamedAttribute)), // 使用 IocNamedAttribute的
  44. c =>
  45. {
  46. // 获取 ioc named 的名称
  47. var iocName = c.Implementation.GetCustomAttribute<IocNamedAttribute>().Name;
  48. c.Named(iocName);
  49. })
  50. .LifestyleTransient());
  51. Configuration.Settings.Providers.Add<IwbSettingProvider>();
  52. IocManager.Register<WeEngineMsgClientManager>();
  53. }
  54. public override void Initialize()
  55. {
  56. IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
  57. }
  58. public override void PostInitialize()
  59. {
  60. MsgClientRegister();
  61. }
  62. private void MsgClientRegister()
  63. {
  64. var MsgClient = IocManager.Resolve<WeEngineMsgClientManager>();
  65. MsgClient.SendMessage( "WeEngine", $"客户端{MsgClient.ClientId}已注册");
  66. MsgClient.SendMessage( "WeApp", $"客户端{MsgClient.ClientId}已注册");
  67. }
  68. }
  69. }