views:

23

answers:

1

I have read the following code:

    public class DalFactory
    {
        private static IDataContext _instance = null;

        static DalFactory()
        {
           string asm = ConfigurationManager.AppSettings["DAL-Assembly"];
           string cls = ConfigurationManager.AppSettings["DAL-Type"];

           Assembly a = Assembly.Load(asm);
           _instance = (IDataContext) a.CreateInstance(cls);
        }

        public IDataContext GetDataContext()
        {
           return _instance
        }
    }

The GetDataContext method will return an instance based on the configuration file. My question is: as the static constructor only initialize once before the first DalFactory instance created, then the configuration file change later won't make effect. That means we can only create a fixed type object after the application running. Is that true?

+1  A: 

Um... That's isn't a question. It is however, true.

In general, config files are not intended to be changed during the run of an application.

James Curran