Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How can I resolve instances without injection in asp net core
When we used spring .NET we could get an instance by something like:
StaticFactory.GetInstance<T>();
In ASP.NET Core, services are available within a request from HttpContext:
HttpContext
HttpContext.RequestServices.GetService(typeof(MyService));
Docs: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.2#request-services
Prefer requesting dependencies as constructor parameters to accessing the RequestServices collection.
RequestServices
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.