question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question]: Can I export decorators with Attributes

See original GitHub issue

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:

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:open
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ipjohnsoncommented, Mar 29, 2020

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.

2reactions
ipjohnsoncommented, Mar 29, 2020

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));
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found