开发者

Dynamically load assemly in static constructor

I have read the fol开发者_StackOverflow社区lowing 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜