Ben Foster
Ben Foster

Reputation: 34800

Property injection not working when using StructureMap and NServiceBus

I've installed the NServiceBus.StructureMap package from NuGet and property injection is no longer working on my Sagas. Here's my configuration code (using the generic host):

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();
    }
}

Upvotes: 1

Views: 607

Answers (1)

Andreas &#214;hlund
Andreas &#214;hlund

Reputation: 5273

Setter injection is not on by default in StructureMap so you need to enable it Autowire setters using StructureMap

Upvotes: 3

Related Questions