Yes, I would say this looks fine. There is no performance issues with
static methods or properties. Your code should look similar to:
sealed class Singleton
{
// this will be instantiated upon first access to the class
// static constructors are thread-safe
private static readonly Singleton _instance = new Singleton();
private Hashtable _types;
private Singleton()
{
// read config file and create/fill _types
}
public static IEnumerable Instance
{
get { return _instance.Values; }
}
private IEnumerable Values
{
get { return _types.Values; }
}
}
On 7/24/06, Robert Rolls <[EMAIL PROTECTED]> wrote:
I use the singleton pattern XyZ.Instance in the following instance - I have a
configuration section that contains a list of types that I need to create.
Within the private constructor I iterate through the config calling
Activator.CreateInstance caching them within a hashtable, accessible via an
indexer or IEnumerable public property. Is this a reasonable use of
Xyz.Instance or should this too be a static.
One thing about static that is a little fuzzy is beforeFieldInit and static
classes/properties/methods etc. Which I think incur a performance penalty?
Rob.
--
Sébastien Lorion
Software Architect / Architecte organique
[EMAIL PROTECTED]
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com