[Question]: Can I export decorators with Attributes
See original GitHub issueConsider 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:
public void ConfigureContainer(IInjectionScope injection)
{
injection.Configure(c =>
{
c.ExportDecorator<ISomeInterface>(
request => new AuditDecorator(request));
});
}
Is there any possible solutions to do:
[Audit]
public SomeImpl : ISomeInterface {
// omitted code
}
public class AuditDecorator : ISomeInterface{
public AuditDecorator(ISomeInterface next)
}
}
// flag attribute to use to map to the decorator
public class AudtiAttribute : Attribute{ }
- currently I wrote a hand-written method which creates factories using reflection. (borrowed from Vladimir Khorikov’s CQRS In Practice course)
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?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Python class attributes decorator
The idea is that an instance like the one above could be then passed to some 'reporting class' that - based on whether...
Read more >Extracting decorated properties from classes in TypeScript
I'm going to assume you know what decorators, type aliases and generics are. The question. How do I create a mapped type that...
Read more >deco before or after export keyword? · Issue #69
export is static, so I think decorating it is impossible. I think that's better to have the class's decorators just before the class...
Read more >How To Use Decorators in TypeScript
Class properties are another place you can use decorators. In this section you will take a look at how to create them. Any...
Read more >Primer on Python Decorators
The @property decorator is used to customize getters and setters for class attributes. Expand the box below for an example using these decorators....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
So essentially only apply the
AuditDecorator
when the implementation is attributed with theAuditAttribute
?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