使用StructureMap和NServiceBus时,属性注入不起作用

时间:2013-05-30 17:16:13

标签: structuremap nservicebus

我已经从NuGet安装了NServiceBus.StructureMap软件包,并且属性注入不再适用于我的Sagas。这是我的配置代码(使用通用主机):

public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
    public void Init()
    {
        Configure.With()
            .StructureMapBuilder(ConfigureStructureMap())
            .XmlSerializer();
    }

    private static IContainer ConfigureStructureMap()
    {
        ObjectFactory.Initialize(cfg =>
        {
            cfg.For<IBarcodeReader>().Use<DataMatrixBarcodeReader>();
            cfg.ForSingletonOf<IDocumentStore>().Use(() => InitializeStore());
            cfg.For<IDocumentSession>().Use(x => x.GetInstance<IDocumentStore>().OpenSession());
        });

        return ObjectFactory.Container;
    }

    private static IDocumentStore InitializeStore()
    {
        return new DocumentStore
        {
            Url = "http://localhost:8080/",
            DefaultDatabase = "db"
        }
        .Initialize();
    }
}

1 个答案:

答案 0 :(得分:3)

默认情况下,在StructureMap中不启用Setter注入,因此您需要启用它Autowire setters using StructureMap