I used following statement to decorate all my ICommandHandlers<>
with Decorator1<>
:
ObjectFactory.Configure(x =>
{
x.For(typeof(ICommandHandler<>)).DecorateAllWith(typeof(Decorator1<>));
});
But because Decorator1<>
implements ICommandHandlers<>
, the Decorator1<>
class decorates itself too.
So, the problem is that the Decorator1
registers inadvertently, when I register all the ICommandHandler<>
's.
How can I filter DecorateWithAll()
to decorate all ICommandHandler<>
, except Decorator1<>
?
ObjectFactory
is obsolete.You can exclude
Decorator1<>
from being registered as a vanillaICommandHandler<>
with code like this:UPDATE
For multiple modules you can use The Registry DSL to compose a portion of your application
Only the Composition Root needs to be aware of all the
Registry
implementations.You even have the option of finding all
Registry
instances at runtime (you still need to ensure all the required assemblies are loaded)