/// <summary> /// Initializes a new instance of the <see cref="MQEventProviderCommandBus"/> class. /// </summary> /// <param name="serviceLocator">服务定位器</param> /// <param name="messageProducerProvider">根据事件去查询消息发布者</param> /// <param name="eventStorager">领域事件的保存方案</param> /// <param name="commandStorager">命令储存</param> public MQEventProviderCommandBus(IServiceLocator serviceLocator, IEventStorager eventStorager, ICommandStorager commandStorager, IMessageProducerProvider messageProducerProvider) : base(serviceLocator) { this.eventBus = new MQEventBus(this, messageProducerProvider); this.eventStorager = eventStorager ?? EmptyEventStreamStorager.Empty; this.commandStorager = commandStorager ?? EmptyCommandStreamStorager.Empty; }
public static ApplicationStartup UseMQEventProviderCommandBus <TCommandContext>(this ApplicationStartup startup, IMessageProducerProvider messageProducerProvider, IEventStorager eventStorager, ICommandStorager commandStorager) where TCommandContext : ICommandContext { if (startup.ServiceRegister == null) { return(startup); } if (startup.Items.ContainsKey("UseMQEventProviderCommandBus")) { return(startup); } if (startup.Items.Remove("UseInprocEventProviderCommandBus")) { throw new ArgumentNullException("系统已经注册同进程模式的命令总线了,两者不同共存"); } /*注册发布事件*/ startup.ServiceRegister.RegisterType(typeof(TCommandContext), typeof(ICommandContext), string.Empty, ComponentLifeStyle.Transient); startup.ServiceRegister.RegisterType(typeof(DefaultEventContext), typeof(IEventContext), string.Empty, ComponentLifeStyle.Transient); startup.ServiceRegister.RegisterInstance(messageProducerProvider ?? new DefaultMessageProducerProvider(), typeof(IMessageProducerProvider), string.Empty); startup.ServiceRegister.RegisterType(typeof(MQEventProviderCommandBus), typeof(ICommandBus), string.Empty, ComponentLifeStyle.Singleton); startup.ServiceRegister.RegisterInstance(eventStorager ?? EmptyEventStreamStorager.Empty, typeof(IEventStorager), string.Empty); startup.ServiceRegister.RegisterInstance(commandStorager ?? EmptyCommandStreamStorager.Empty, typeof(ICommandStorager), string.Empty); //注入handler类型的对象 startup.UseInjectingCommandHandlerEventHandler(ComponentLifeStyle.Singleton); startup.Items["UseMQEventProviderCommandBus"] = "t"; return(startup); }
public static ApplicationStartup UseMQEventProviderCommandBus <TCommandContext>(this ApplicationStartup startup, IMessageProducerProvider messageProducerProvider, IEventStorager eventStorager) where TCommandContext : ICommandContext { return(UseMQEventProviderCommandBus <TCommandContext>(startup, messageProducerProvider, eventStorager, EmptyCommandStreamStorager.Empty)); }
public static ApplicationStartup UseMQEventProviderCommandBus(this ApplicationStartup startup, IMessageProducerProvider messageProducerProvider) { return(UseMQEventProviderCommandBus <DefaultCommandContext>(startup, messageProducerProvider, EmptyEventStreamStorager.Empty)); }
/// <summary> /// Initializes a new instance of the <see cref="MQCommandStreamStorager"/> class. /// </summary> /// <param name="messageProducerProvider">The message producer.</param> public MQCommandStreamStorager(IMessageProducerProvider messageProducerProvider) : this(messageProducerProvider.MessageProducer, SerializeEnvironment.JsonSerializer, null) { }
/// <summary> /// Initializes a new instance of the <see cref="MQEventBus"/> class. /// </summary> /// <param name="commandBus"></param> /// <param name="messageProducerProvider">The message producer.</param> public MQEventBus(ICommandBus commandBus, IMessageProducerProvider messageProducerProvider) { this.commandBus = commandBus; this.messageProducerProvider = messageProducerProvider; }