View Single Post
  #5 (permalink)  
Old October 15th, 2007, 09:06 AM
jimibt jimibt is offline
Friend of Wrox
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts

Another little TIP. based on a question by trystanc on this forum, he asked about the thread safety of singleton patterns. after a bit of research, i came up with a minor change that addresses the failure in the TBH implementation. anyway, here's a link to the original thread, as well as my code changes below:

here's how my ForumsProvider (DAL\Provider\ForumsProvider.cs) 'intro' looks now:

namespace MB.TheBeerHouse.DAL
    public abstract class ForumsProvider : DataAccess
        static private readonly ForumsProvider _instance = (ForumsProvider)Activator.CreateInstance(
                    Type.GetType(Globals.Settings.Forums.ProviderType) );

        static ForumsProvider() { }

        static public ForumsProvider Instance
                return _instance;

        public ForumsProvider()
            this.ConnectionString = Globals.Settings.Forums.ConnectionString;
            this.EnableCaching = Globals.Settings.Forums.EnableCaching;
            this.CacheDuration = Globals.Settings.Forums.CacheDuration;
        // other code below unchanged

hope this makes sense.