Open slimshader opened 5 years ago
For those who stumble across this:
_container.BindInterfacesAndSelfTo<Mediator>().AsTransient(); _container.BindInterfacesAndSelfTo<MediatrPassThroughHandler>().AsTransient(); _container.Bind<ServiceFactory>().FromMethod(ctx => (t) => ctx.Container.TryResolve(t)).AsTransient();
Worked for me.
For those who stumble across this:
_container.BindInterfacesAndSelfTo<Mediator>().AsTransient(); _container.BindInterfacesAndSelfTo<MediatrPassThroughHandler>().AsTransient(); _container.Bind<ServiceFactory>().FromMethod(ctx => (t) => ctx.Container.TryResolve(t)).AsTransient();
Worked for me.
What is MediatrPassThroughHandler?
Sorry I should have explained
MediatR has no dependencies. You will need to configure a single factory delegate (2), used to instantiate all handlers (3), pipeline behaviors, and pre/post-processors.
You will need to configure two dependencies: first, the mediator itself (1). The other dependency is the factory delegate, ServiceFactory (2).
//Setup the Mediator (1)
_container.BindInterfacesAndSelfTo
//Setup the ServiceFactory (2)
_container.Bind
//Setup each of your IRequestHandlers (3)
_container.BindInterfacesAndSelfTo
Sorry I should have explained
MediatR has no dependencies. You will need to configure a single factory delegate (2), used to instantiate all handlers (3), pipeline behaviors, and pre/post-processors. You will need to configure two dependencies: first, the mediator itself (1). The other dependency is the factory delegate, ServiceFactory (2).
//Setup the Mediator (1) _container.BindInterfacesAndSelfTo<Mediator>().AsTransient(); //Setup the ServiceFactory (2) _container.Bind<ServiceFactory>().FromMethod(ctx => (t) => ctx.Container.TryResolve(t)).AsTransient(); //Setup each of your IRequestHandlers (3) _container.BindInterfacesAndSelfTo<StartApplicationHandler>().AsTransient(); _container.BindInterfacesAndSelfTo<ShowWindowHandler>().AsTransient();
Ah, this I know how to configure :) I was hoping for generic configuration as per MediatR container examples that resolve IRequestHandler
EDIT: I also think you want them .AsSingle(), especially Mediator and ServiceFactory bindings EDIT2: I would suggest to not do BindInterfacesAndSelfTo<> for handlers and use BindInterfacesTo<> (without the "Self") part, as this exposes implementation class while it should only be used via interfaces
Honestly I gave up on trying to auto register my handlers, it is certainly NOT straight forward but with a little reflection magic its do-able. I will look into it again when I get the chance!
Hey, how would MediatR Container configuration look for Extenject? I lookned into Ninject example (as I recall Zenject/Extenject) were based on it but it doesnt really help much.