We have a multi-tenant application with running site instances stored in a ConcurrentDictionary<string, SiteInstance>, where string is the hostname of the site.
We now have the requirement to support multiple hostnames per site instance. As a temporary solution I’m searching first by key and if no match is found, then performing a LINQ query against the dictionary to find an instance with a matching hostname.
Is there a better/faster performing solution here?
Note: The list of hostnames mapped to each site instance is variable.
Could you not use multiple key-value pairs with the same
SiteInstanceand different keys?The hostnames must be unique. To access distinct
SiteInstanceobjects (edit due to comments), you could either use an additionalHashSet<SiteInstance>or use LINQ (not threadsafe, however):