rebus-org / Rebus.Autofac

:bus: Autofac container adapter for Rebus
https://mookid.dk/category/rebus
Other
12 stars 11 forks source link

How to resolve in new Configurer API? #6

Closed ben-jacobs closed 6 years ago

ben-jacobs commented 6 years ago

With the old API, we could access IComponentContext to resolve components used in the Rebus configuration - e.g. IDocumentStore if using the RavenDB connectors.

e.g.

var busConfiguration = Rebus.Config.Configure.With(new AutofacContainerAdapter(c.Resolve<IContainer>())) .Logging(l => l.Serilog(Log.Logger)) .Timeouts(t => t.StoreInRavenDb(c.Resolve<IDocumentStore>())) .Sagas(s => s.StoreInRavenDb(c.Resolve<IDocumentStore>())) .Transport(t => t.UseRabbitMq(connectionString, inputQueueName))

How can we access the ComponentContext with this new API to allow for resolving components for the transport registrations etc?

Cheers.

mookid8000 commented 6 years ago

Damn, I thought that was possible 🙁 I must have accidentally removed that parameter. I'll bring in an overload that makes it possible... stay tuned

mookid8000 commented 6 years ago

it's out in 5.1.0 in a few seconds – thanks for reporting this issue! 😄

mookid8000 commented 6 years ago

so you should be able to do this now:

builder.RegisterRebus((configurer, context) => configurer
    .Transport(t => t.UseMsmq("my-queue")
    .Sagas(t => t.StoreInRavenDb(c.Resolve<IDocumentStore>())
    .Timeouts(t => t.StoreInRavenDb(c.Resolve<IDocumentStore>())))))))));

PS: I put some extra ) in there – couldn't keep count in my head