© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
13 replies
Turn2Jesus2

Immutable Service Options

I have a service which mutates its options. I discovered that IOptions<T> creates a singleton and all of the unit tests I'm running all get the same options but unrelated services are mutating the options and other services are seeing those changes.

I'd like to have a simple solution that would ensure the options are not mutated and should something try to, it breaks or doesn't compile or whatever.
If there's a simple solution, what is it?
Someone in the chat yesterday mentioned something about IImmutable, but I don't know the specifics.
I saw something about an ImmutableDictionary, but I'd like the whole class to be.

Ideas?
I kind of think this should be a standard of some sort.
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

String : Immutable reference type
C#CC# / help
3y ago
✅ Why string are immutable?
C#CC# / help
4y ago
Updating Immutable object with ef
C#CC# / help
2y ago
✅ Immutable object with mutable clone
C#CC# / help
3y ago