-1

I want to implement a configuration helper.

The usage will be something like this:

var companyName = ConfigHelper.Company.Name;
var redirectURL = ConfigHelper.URLs.DefaultRedirectURL; 

As you can see in the above examples, I have ConfigHelper which should not require an instance, however it will consist of sub classes (Company and URLs), and here I want access to the properties (not methods).

I want this all done without any class instances required, and not sure if I should be using static / singleton.

E.g. will ConfigHelper be defined as static? Will the sub classes be defined as regular classes and will they become static properties of ConfigHelper?

2 Answers 2

1
public static class Company
{
    public const string Name = "Company Name";
}

public static class ConfigHelper
{
    public static readonly Company = new Company();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Yes you're on the right track, ConfigHelper will be a static class and the properties will just be regular classes, but those will be instances.

For example:

public class Company
{

    public string Name { get; set; }

}

public static class ConfigHelper
{

    static ConfigHelper()
    {
        Company = new Company();
    }

    public static Company Company { get; private set; }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.