Dependency Injection wiring lost
See original GitHub issueHi,
Thanks for the great library!
I have run into an issue where variables are lost that are setup in the constructor via the DI framework. I use StructureMap to wire the class up, this wiring instantiates a field that I need to reference in a method that I am applying advice to. The issue is only prevalent when I place the attribute at the top of the class, when I place the attribute on top of the method in question, all works _fine!
This is the relevant code:
RepositoryClass:
[RepositoryExceptionAdvice] _<-- _settings is null if attribute is placed here_
public class ExampleRepository : IExampleRepository
{
private readonly ISettings _settings;
public ComponentTermsRepository(ISettings settings)
{
_settings = settings;
}
//Advice
_<-- _settings is fine if attribute is placed here_
public async Task<List<Example>> List(Guid? ExampleId)
{
var test = _settings.TenantId _<- Settings here is null_
}
}
**Advice Class**
public class RepositoryExceptionAdvice : Attribute, IMethodAsyncAdvice
{
public async Task Advise(MethodAsyncAdviceContext context)
{
try
{
if (context.IsTargetMethodAsync)
{
await context.ProceedAsync();
}
}
catch (DatabaseException e)
{
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Wiring not done correctly with PyInstaller #438
Hi, having the same issue. Python 3.8.8; PyInstaller 4.3; dependency-injector 4.35.2. I too have project running when I execute it as a python ......
Read more >Determining missing dependencies statically when using ...
When using a dependency injection container, missing dependencies are detected when you execute resolve. This is at runtime.
Read more >The problem with dependency injection frameworks
I gave up on dependency injection frameworks a while ago. Now there's just some "wiring" code somewhere that wires up the components.
Read more >How to catch and fix a Guice dependency injection issue ...
RunTime Exceptions from Incorrect Dependency Injection Wiring ... Sensei to pick up the missing requestStaticInjection since all our Guice ...
Read more >Dependency Injection — Back to the Basics | by Luís Soares
Wiring. Let's put it all together. Wiring means the assembling of your app's components — all the DIs happening in one place, forming...
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
Eish, just got your second response, so you can ignore the above comment.
Yes, that was a bit stupid of me blush
What would the recommended way be to ignore the advice for the constructor? Would this be the best approach:
if (!context.TargetMethod.IsConstructor) [proceed]
The idea is that a
IMethodAsyncAdvice
works fine with both sync and async methods.