Open shahabganji opened 4 years ago
So essentially only apply the AuditDecorator
when the implementation is attributed with the AuditAttribute
?
If that's the case you can use the When.MeetsCondition
method to decide when the decorator should be applied.
You could do something like this
.When.MeetsCondition((strategy,staticContext) => strategy.ActivationType.GetCustomAttributes().Any(a => a is AuditAttribute));
@ipjohnson Thanks for the prompt reply.
That is exactly the case, but I am afraid that c.ExportDecorator<ISomeInterface>
has the return type of void
and one cannot indicate the When
conditions. here and its implementation
-------- EDIT -------
But the followin has worked:
c.ExportDecorator( typeof(AuditDecorator))
.When.MeetsCondition(
(strategy, staticContext)
=> strategy.ActivationType.GetCustomAttributes(false)
.Any(a => a is AuditAttribute))
.As(typeof(ISomeInterface));
Ok glad that worked with slightly different syntax. I'll open an issue up to add When configuration to the ExportDecorator func. That's just an over sight on my part.
Is there any way to change the order of decorators as well? for instance based on the way the attributes are applied to the concrete class?
For the moment it's going to be dependent on registration order. That said this seems like a reasonable feature to ask for.
I should have time in the coming week to implement these two features and get a release out.
That is great 💪 👍 and could you please label this issue as question
so that other devs might better find it if they have the same problem 🙏
And thank you for the great support 🙂
I've pushed out a nuget package with both changes
I’ll check it tonight. 🙏🏻👍🏻
Am 04.04.2020 um 20:25 schrieb Ian Johnson notifications@github.com:
I've pushed out a nuget package with both changes
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
@ipjohnson I checked both and it looks great 👍 Thanks for the time and effort.
Consider a situation where I have a default implementation for an interface and some decorators, now I could use grace to register my decorators like the following:
Is there any possible solutions to do:
I don't know how efficient this is, I want to know is there any way to give all the boilerplate code to the IoC?