In C# with typical dependency injection services setup. I have my own custom service registered and it works fine. However, I find it is being invoked (injected) at times that I didn’t expect. So I want to debug and know what code wants my service to be injected? I can’t figure out how to do that.
Example:
// Program startup I register my service as normal.
services.AddTransient<MyCustomService>();
// And other stuff...
services.AddTransient<SomeOtherThing>();
services.AddTransient<AndAnother>();
services.AddTransient<AndMore>();
public class MyCustomService
{
public MyCustomService()
{
// My service works fine, but can it know who is requesting it?
// WHO IS REQUESTING ME FROM DI?
// Note that this is not intended for some weird hacky functionality,
// rather I'm trying to debug why my service is being invoked more than expected.
}
}
// Some other services/controllers/etc that are pulling in MyCustomService from DI
...
public SomeOtherThing(MyCustomService mcs) { ... }
...
public AndAnother(MyCustomService mcs) { ... }
...
public AndMore(MyCustomService mcs) { ... }
...