Inject dependency into a class attr
See original GitHub issueHello,
Sorry if this question already has been answered somewhere but I went through the doc extensively and couldn’t find anything.
I would like to inject a dependency for a class attribute, but couldn’t find any way of doing it.
Something similar from python-inject:
class User(object):
cache = inject.attr(Cache)
Thanks for your help
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to use dependency injection with an attribute?
Strictly speaking, we cannot use dependency injection to inject a dependency into an attribute. Attributes are for metadata not behavior. [ ...
Read more >Dependency Injection in ASP.NET Core Attributes
When working with ASP.NET core one of the features now front and centre is dependency injection, built into the framework.
Read more >Dependency Injection in Attributes: don't do it! - NET Junkie
By registering a custom IFilterProvider and relying on property injection for the dependencies, you are able to inject dependencies into ...
Read more >C# – How to use dependency injection with an attribute
What's the best way to inject something into an attribute class? Strictly speaking, we cannot use dependency injection to inject a dependency into...
Read more >InjectAttribute Class (Microsoft.AspNetCore.Components)
Indicates that the associated property should have a value injected from the service ... Inherited=true)] public sealed class InjectAttribute : Attribute
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
Hello @brunopereira27 ,
You can do it with
Factory
provider:You didn’t find it because I didn’t document that. I’m sorry about that. I already have a backlog item to update documentation.
Closing this issue. Feel free to comment if anything.