How to use different .settings files for different environments in .NET?

前端 未结 6 900
温柔的废话
温柔的废话 2021-02-02 01:11

.NET allows you to use .settings files to manage application settings. I would like to store Production, Development and Test settings separately in a way that I can do somethi

6条回答
  •  眼角桃花
    2021-02-02 01:54

    One thought is that switching between a series of static values sounds like a rather fraught way of doing things. I would suggest looking up the Singleton pattern. This pattern gives you a single class instance that is shared between all references to the class, but when it's first loaded you can do your normal initialisation bits to check your environment and set the values accordingly.

    Equally, rather than using switches to act on different classes, wouldn't you be looking at designing one Interface, and having each class implement that interface?

提交回复
热议问题