Closed cnshenj closed 5 years ago
Current ExportDecorator solution:
Hi @cnshenj
Which interception library are you planning to use (since Grace doesn't have one built in)?
Castle DynamicProxy. But I am open to suggestions if a library can do what I want to do (with reasonable performance).
I've added a simple C# extension that applies decorators to exported classes that have a specific attribute.
Let me know if that works for you
Thanks for the extension, I believe it will work. I just need to modify it to accept a Predicte<IActivationStrategy>
so it can be used in other scenarios.
One question: you already checked the attribute once at the beginning of the foreach
loop, why adding the same check again in .When.MeetsCondition()
?
The reason for the second check is because we’re intercepting the interface and there is a possibility for more than one type registered with the container.
Put it another way the decorator registration says I want to use this decorator for this interface when the implementation is type X.
Makes sense. And I can confirm it works.
I made two changes:
Predicte<IActivationStrategy>
so it can be used in more scenarios.strategy.ExportAs.First()
, I use foreach (var serviceType in strategy.ExportAs)
to intercept all service types in the strategy.@cnshenj both good modifications. I'll see about updating the implementation in the tests for anyone that's interested
Preparation:
Expected:
Requirement:
Foo2
andBar
will be intercepted, because they are[Slow]
.Foo1
is not intercepted, although it implements the same interface asFoo2
.