Does the global configuration class have a bad one?

I am currently building on my personal website. I use the Config global static class to store all the custom parameters that may be required for a change that is semi-global. So now it looks like this:

public static class Config
{
    public static string ConnectionString = "mongodb://localhost";
    //more configuration options..
    public static MongoDB.Driver.MongoDatabase GetDB(){
        MongoServer server = MongoServer.Create(Config.ConnectionString);
        MongoDatabase db = server.GetDatabase(Config.Database);
        return db;
    }
    public static Markdown GetMarkdown(){
        var options=new MarkdownOptions(){
            AutoHyperlink=true,
            AutoNewlines=false,
            EmptyElementSuffix=" />",
            LinkEmails=false,
            StrictBoldItalic=true
        };
        var m=new Markdown(options);
        return m;

    }
}

Does such a global configuration class use this anti-pattern? In addition, I prefer the connection strings to be outside of web.config. I like my web.config as little as possible.

+3
source share
5 answers

Well, out of 3 members, only 1 is really a config, the other two are really a utility.

, , , .

+2

- , , . , . web.config, ( ).

+2

Earlz,

, - , web.config. , web.config

<connectionStrings configSource="config\yourpath\connectionStrings.config"/>

, . ,

+1

- , GetMarkdown ConnectionString , , . GetMarkdown GetDB factory , , , .

, , , , . , .

+1
source

We have moved our configuration settings to the database. This facilitates the transition from Dev to QA to Prod. Blog post here.

In this regard, we put the connection string aside in WebEnvironment.config. Now we can promote our code with changes to web.config and not worry about the connection string. This blog post is here.

0
source

Source: https://habr.com/ru/post/1796580/


All Articles