MassTransit和简单进样器 [英] MassTransit and Simple Injector

查看:99
本文介绍了MassTransit和简单进样器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 .NET的MassTransit分布式应用程序框架.根据该网站的说法, MassTransit是从一开始就以IoC的概念构建的容器,并为少数几个主流" IoC容器提供支持库.目前(有)NuGet软件包可用于Autofac,StructureMap,Castle Windsor,Ninject&团结.

I'm reviewing the MassTransit Distributed Application Framework for .NET. According to the website MassTransit has been built from the beginning with the concept of an IoC container being involved and provides support libraries for a handful of the more "mainstream" IoC Containers. There are (currently) NuGet packages available for Autofac, StructureMap, Castle Windsor, Ninject & Unity.

我已选择简单注入器作为我选择的IoC容器

I have selected Simple Injector as my IoC container of choice for performance reasons but I am unable to find an integration library adding support for Simple Injector to MassTransit.

有人尝试过这个吗,让它正常工作,并提供一些代码来帮助我入门?

Has anyone tried this, got it to work and have some code available to get me started?

推荐答案

我不熟悉MassTransit,但是在查看了

I'm not familiar with MassTransit, but after looking at the configuration examples for the other containers, this is what I came up with:

public static void main(string[] args)
{
    var container = new Container();

    var consumers = container.GetTypesToRegister(typeof(IConsumer),
        applicationAssemblies);

    foreach (Type consumer in consumers)
        container.Register(consumer);

    IServiceBus bus = ServiceBusFactory.New(sbc => {
        //other configuration options

        sbc.Subscribe(subs => {
            foreach (var consumer in consumers)
                subs.Consumer(consumer);
        });
    });

    container.RegisterSingle<IServiceBus>(bus);

    container.Verify();
}

这篇关于MassTransit和简单进样器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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