public EventProcessManager(ILogger <EventProcessManager> logger, ILifetimeScope lifetimeScope, IEventBus eventBus, ISubscribeProxyFactory subscribeFactory) { this.logger = logger; this.lifetimeScope = lifetimeScope; this.eventBus = eventBus; this.subscribeFactory = subscribeFactory; }
/// <summary> /// 构造一个管道配置 /// </summary> /// <typeparam name="Tservice"></typeparam> /// <typeparam name="TEvent"></typeparam> /// <param name="lifetimeScope"></param> /// <param name="subscribeFactory"></param> /// <param name="eventBus"></param> /// <param name="method"></param> /// <returns></returns> public static ProcessConfigureBase Build <Tservice, TEvent>(ILifetimeScope lifetimeScope, ISubscribeProxyFactory subscribeFactory, IEventBus eventBus, Func <TEvent, Task> method) where Tservice : class where TEvent : EventProcessBase { //获取委托订阅器的订阅主题 var topic = method.Method.GetCustomAttribute <EventHandlerAttribute>().Topic; //构造配置类型的泛型 var processconfigure = ProcessConfigureType.MakeGenericType(typeof(Tservice), method.Method.DeclaringType, typeof(TEvent)); //创建配置实例 var instance = (ProcessConfigureBase)Activator.CreateInstance(processconfigure, lifetimeScope, topic, eventBus, method); //将实例的代理委托注册到订阅器 subscribeFactory.Register <EventProcessPacker <TEvent> >(topic, instance.HandleInvoke); return(instance); }