In a .net core 5 or 6 api, if I have a dependency:
services.AddScoped<IMyDependency>((svc) =>
{
return new MyDependency(appSettings.ConnectionStrings.MyDB);
});
and I have a class that uses the dependency:
public class MyClass
{
public MyClass(IMyDependency dependency)
{
...
}
}
How do I instantiate the class so that the dependency is injected into the constructor? In a controller, this is done for me when the controller is instantiated. How do I do it for my own classes?
I can use services.GetServices explicitly, but I think that is frowned upon.