© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
Relevant

❔ ✅ Register instance of List as singleton

This feels like a dumb question, but I'm trying to keep a singleton instance of a List that can be added to by different areas of the application. This doesn't seem to work:

builder.Services.AddSingleton<List<MyThing>>();
builder.Services.AddSingleton<List<MyThing>>();


or

List<MyThing> myThings = new();
builder.Services.AddSingleton(myThings);
List<MyThing> myThings = new();
builder.Services.AddSingleton(myThings);
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Settings model as a singleton in WPF
C#CC# / help
3y ago
✅ Singleton Class
C#CC# / help
3y ago
❔ Singleton Pattern
C#CC# / help
4y ago
List as a field of an object. [Answered]
C#CC# / help
4y ago