带有membus和ioc容器的SetHandlerInterface()的多种类型 [英] multiple types for SetHandlerInterface() with membus and ioc container

查看:95
本文介绍了带有membus和ioc容器的SetHandlerInterface()的多种类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遍历演示CQRS代码命令和事件处理程序分别连接如下:

Going over demo CQRS code here the command and event handlers are wired up separately as below:

public interface CommandHandler<in T>
{
    void Handle(T command);
}

public interface EventHandler<in T>
{
    void Handle(T @event);
}

bus = BusSetup.StartWith<Conservative>()
       .Apply<FlexibleSubscribeAdapter>(a =>
       {
           a.ByInterface(typeof(IHandleEvent<>));
           a.ByInterface(typeof(IHandleCommand<>));
       })
       .Construct();

我正在使用与membus挂钩的IoC容器,并且通过在我的容器中实现IEnumerable<object> GetAllInstances(Type desiredType)接口来实现梦想,但是与演示此注册方法的演示不同,我无法为单独的命令和事件拆分接口:

I am using an IoC container hooked in with membus and it works a dream by implementing the IEnumerable<object> GetAllInstances(Type desiredType) interface with my container, however unlike the demo with this method of registration I cannot split out the interfaces for separate commands and events:

this.Bus = BusSetup.StartWith<Conservative>()
    .Apply <IoCSupport>(c =>
        {
            c
            .SetAdapter(SimpleInjectorWiring.Instance)
            .SetHandlerInterface(typeof(CommandHandler<>))
            /*.SetHandlerInterface(typeof(EventHandler<>))*/;
            // only CommandHandler or EventHandler can be used - not both
        })
    .Construct();

有人可以让我知道是否可以解决这个问题,以便我们可以注册任意数量的类型吗?

Can anyone please let me know if there any way around this so we can register for an arbitrary number of types?

推荐答案

恐怕当前版本的MemBus无法做到这一点-出于特殊原因,请注意.我知道即使底层基础结构相同,也能够区分事件和命令还是有道理的.

I am afraid that the current version of MemBus cannot do that - for no particular reason, mind you. I know that it makes sense to be able to distinguish between Events and Commands, even though the underlying infrastructure is the same.

目前唯一的解决方法是使用单个接口将IOC挂接到MemBus.

The only workaround right now is to use a single interface to hook the IOC into MemBus.

如果应该将这种功能引入MemBus,则必须考虑到IOC容器的查找机制应如何.它可能必须请求所有接口的所有处理程序,或者必须采用某种方式对事件和命令消息"进行分类/区分.

If such a feature should be introduced into MemBus one has to think how the lookup mechanism into the IOC Container should look like. It would probably have to request all handlers of all interfaces, or some way to categorize / distinguish between event and command "messages" would have to be introduced.

这篇关于带有membus和ioc容器的SetHandlerInterface()的多种类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆