Dibzmania Dibzmania - 3 months ago 16
ASP.NET (C#) Question

What is the best approach to a web client setting up configurations for a library it uses

I have developed a simple library in C# which is to be used by .Net Web clients.

The library needs a couple of configurations to be done to achieve the expected functionality. Right now in my library code, I am reading them from the web configuration file and have asked the clients to configure them in their web.config or app.config.

But client has security concerns and wants the ability to store those configuration in it's database.What would be a good approach to let the clients pass those configurations to my library (irrespective of where they store them).
Are C# interfaces the way to go (Let clients implement a interface and pass it to the library during initialisation may be)?


A simple approach would be to expose some sort of configuration class containing public properties that can be set by the client. It might look something like this:

public static class Settings
    public static string ApplicationName { get; set; }
    public static string ServerName { get; set; }
    public static int PortNumber { get; set; }

    public static void Initialise(string applicationName, string serverName, int portNumber)
        ApplicationName = applicationName;
        ServerName = serverName;
        PortNumber = portNumber;

The client can pass through the appropriate settings by calling:

Settings.Initialise("Example App", "localhost", 8080);

And your library can access those settings by calling: