Using StructureMap, is it possible to have a singleton object for each value of an argument?
For example, say I want to maintain a different singleton for each website in a multi-tenancy web app:
For<ISiteSettings>().Singleton().Use<SiteSettings>();
I want to maintain a different singleton object corresponding to each site:
ObjectFactory.With<string>(requestHost).GetInstance<ISiteSettings>();
Currently, it seems to create a new object every time I try to resolve ISiteSettings.
The Singleton scope really means singleton – there can be only one instance. For your scenario, I would recommend you implement a custom ILifecycle which uses the requestHost (which I assume can be pulled out of HttpContext) to return the appropriate cached instance. Take a look at the StructureMap source code to see how the other ILifecycles are implemented.
When you register
For<ISiteSettings>, there is an option to specify your own ILifecycle, instead of using one of the ones built in.