{
  "id": 13062838,
  "title": ".NET: how to consume a scoped service from a singleton?",
  "url": "https://urgent.news/2026/10/09/net-how-to-consume-a-scoped-service-from-a-singleton",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-09T07:48:25.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/anton9/net-how-to-consume-a-scoped-service-from-a-singleton-58k9"
  },
  "original_language": "en",
  "account": "A common challenge in .NET programming is consuming a scoped service from a singleton. Microsoft's documentation discourages the usage of the Service Locator pattern. The typical solution involves creating a scope on demand using IServiceScopeFactory. However, this approach still carries the disadvantages of the Service Locator pattern. To address this issue, the author proposes creating a thin wrapper, MyWrappedScoped, that allows scoped services to act like singletons. MyWrappedScoped takes an IServiceScopeFactory in its constructor and provides a Forward method to seamlessly call scoped service methods as if they were singleton methods. This approach avoids the pitfalls of the Service Locator pattern while maintaining the desired functionality.",
  "summary": "This is a short post about a very specific C#/.NET topic. They say one needs to pick their battles. Here I decided to pick a battle with a StackOverflow answer from 2018 and a couple of fellow tech bloggers, because I have opinions. This is not exactly a tutorial, so I assume the reader has some basic understanding of .NET, its DI mechanisms and service lifetimes. Q: In .NET, how to consume a…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}