Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MassTransit和Unity IOC集装箱集成_C#_.net_Dependency Injection_Unity Container_Masstransit - Fatal编程技术网

C# MassTransit和Unity IOC集装箱集成

C# MassTransit和Unity IOC集装箱集成,c#,.net,dependency-injection,unity-container,masstransit,C#,.net,Dependency Injection,Unity Container,Masstransit,我与MassTransit和我的IoC容器(Unity)在命名注册方面存在问题。为了澄清我的问题,我有以下代码: public class CommandHandlerToConsumerAdapter<T> : Consumes<T>.All where T : class, ICommand { private readonly ICommandHandler<T> m_commandHandler; //objec

我与MassTransit和我的IoC容器(Unity)在命名注册方面存在问题。为了澄清我的问题,我有以下代码:

public class CommandHandlerToConsumerAdapter<T> : Consumes<T>.All
        where T : class, ICommand
    {
        private readonly ICommandHandler<T> m_commandHandler; //object responsible for performing the expected actions with the received message

        public CommandHandlerToConsumerAdapter(ICommandHandler<T> _commandHandler)
        {
            m_commandHandler = _commandHandler; //injected property
        }

        public void Consume(T _message) //receives the message
        {
            m_commandHandler.Handle(_message); //does the logic
        }
    }
}
然后我希望这两个类都通过适配器类接收消息。为此,我按如下方式注册它们,将一个不同的
ICommandHandler
实现注入到每个实现中:

container.RegisterType<Consumes<Command>.All, CommandHandlerToConsumerAdapter<Command>>("CommandLogic", new InjectionConstructor(new ResolvedParameter(typeof(ICommandHandler<Command>), "CommandLogic")));
container.RegisterType<Consumes<Command>.All, CommandHandlerToConsumerAdapter<Command>> ("CommandHandler", new InjectionConstructor(new ResolvedParameter(typeof(ICommandHandler<Command>), "CommandHandler")));
container.RegisterType(“CommandLogic”,新注入构造函数(新解析参数(typeof(ICommandHandler),“CommandLogic”));
container.RegisterType(“CommandHandler”,新注入构造函数(新解析参数(typeof(ICommandHandler),“CommandHandler”));
但是,通过这样做,我没有达到预期的结果,即两个类
commandHandlerToConsumerapter
,都具有注入属性
CommandLogic
,和
commandHandlerToConsumerapter
,都具有注入属性
CommandHandler
,都是,通过my
CommandHandlerToConsumeradPter
适配器类,分别通过对象
CommandLogic
CommandHandler
接收类型为
Command
的消息,并相应地处理它们


目前,只有最后注册的类正在接收消息并对其进行处理。有人知道我如何通过这种方法订阅相同的消息类型吗?也许我在IoC容器的注册中弄错了什么…

我看不出你发布的代码有什么问题。我已经试过了,可以用
container.ResolveAll()解析这两个实例。您可以发布解析命令处理程序集合和对它们的调用的代码吗
container.RegisterType<Consumes<Command>.All, CommandHandlerToConsumerAdapter<Command>>("CommandLogic", new InjectionConstructor(new ResolvedParameter(typeof(ICommandHandler<Command>), "CommandLogic")));
container.RegisterType<Consumes<Command>.All, CommandHandlerToConsumerAdapter<Command>> ("CommandHandler", new InjectionConstructor(new ResolvedParameter(typeof(ICommandHandler<Command>), "CommandHandler")));