I'm using Jimmy Bogard's Mediatr and trying to use the pipleine example here
my problem is that although I can get all my closing generic types like so
kernel.Bind(
x =>
x.FromAssemblyContaining<ExpensiveRequest>()
.SelectAllClasses()
.InheritedFrom(typeof (IRequestHandler<,>)).BindAllInterfaces()
I can't decorate them all with the MediatorPipeline.
So if I were using StructureMap I could use something like this
cfg.For(typeof(IRequestHandler<,>)).DecorateAllWith(typeof(MediatorPipeline<,>));
I can't find how I would achieve it with Ninject so that when when my Mediator is called it uses the Mediator pipeline and then down to the original Handler
Couple of ways to do this. You can either do a convention based scan which you are already doing, and add a contextual binding to the end of it:
kernel.Bind(x => x.FromAssemblyContaining<ExpensiveRequest>()
.SelectAllClasses()
.InheritedFrom(typeof(IRequestHandler<,>))
.BindAllInterfaces();
.Configure(c => c.WhenInjectedExactlyInto(typeof(MediatorPipeline<,>));
Then just do the exact same thing again without the WhenInjectedExactlyInto
context filter:
kernel.Bind(x => x.FromAssemblyContaining<ExpensiveRequest>()
.SelectAllClasses()
.InheritedFrom(typeof(IRequestHandler<,>))
.BindAllInterfaces();
This would require two assembly scans to happen though.
Another way would be to write an IBindingGenerator, and perform multiple bindings in there - one with WhenInjectedExactlyInto
and another without. This would then only require a single convention based binding using the .BindWith<MyBindingGenerator>()
syntax instead of .BindAllInterfaces()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With