Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:45:11+00:00 2026-06-14T07:45:11+00:00

My system currently runs in differents environments. I got a Environment enum on my

  • 0

My system currently runs in differents environments.

I got a Environment enum on my system, something like this

public enum Environment {

    [UsePayPal(false)]
    [ServerInstallDir("InstallPathOnServer")]
    [IntegrationSystemURI("localhost/someFakeURI")]
    [UpdateSomeInfo(true)]
    [QueuePrefix("DEV")]
    [UseCache(false)]
    [AnotherSystemURI("localhost/anotherFakeURI")]
    Development = 0,

    [UsePayPal(false)]
    [ServerInstallDir("InstallPathOnBUILDServer")]
    [IntegrationSystemURI("build-server/someFakeURI")]
    [UpdateSomeInfo(true)]
    [QueuePrefix("QA")]
    [UseCache(false)]
    [AnotherSystemURI("build-server/anotherFakeURI")]
    QA = 1,

    [UsePayPal(true)]
    [ServerInstallDir("InstallPathOnServer")]
    [IntegrationSystemURI("someservice.com/URI")]
    [UpdateSomeInfo(true)]
    [QueuePrefix("PRD")]
    [UseCache(true)]
    [AnotherSystemURI("anotherservice/URI")]
    Production = 2,
}

I’m working like this, because I dont like code like

if(CURRENT_ENVIRONMENT == Environment.QA || CURRENT_ENVIRONMENT == Environment.DEV)
    EnableCache()

or

if(CURRENT_ENVIRONMENT == Environment.QA || CURRENT_ENVIRONMENT == Environment.DEV){
    DoSomeStuff();
}

because I think that’s scatter my logic all over the system, and not on a single point.

If some day I add another Test Enviroment, I dont need to go all over my code to see if I work like on Development, QA or Production enviroment.

Ok, but, with all that config I may end up with too maby attributes on my Enum, lets say, in 3 years each enum value will have 15~20 attributes, and that looks weird.

What do you guys think? How do you usually handle this situation? Its really too many attributes, or thats ok?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:45:12+00:00Added an answer on June 14, 2026 at 7:45 am

    Create an Environment class with a private constructor and as many properties as you need to describe the environment, and expose static readonly instances as public properties. You can also have an Environment.Current property that points to one of these instances.

    Example code:

    sealed class Environment
    {
        // The current environment is going to be one of these -- 1:1 mapping to enum values
        // You might also make these properties if there's fine print pointing towards that
        public static readonly Environment TestEnvironment;
        public static readonly Environment ProductionEnvironment;
    
        // Access the environment through this
        public static Environment Current { get; set; }
    
        static Environment()
        {
            TestEnvironment = new Environment {
                UsePayPal = false,
                ServerInstallDir = "/test"
            };
            ProductionEnvironment = new Environment { 
                UsePayPal = true, 
                ServerInstallDir = "/prod"
            };
        }
    
        // Environment propeties here:
        public bool UsePayPal { get; private set; }
        public string ServerInstallDir { get; private set; }
    
        // We don't want anyone to create "unauthorized" instances of Environment
        private Environment() {}
    }
    

    Use it like:

    Environment.Current = Environment.TestEnvironment;
    
    // later on...
    Console.WriteLine(Environment.Current.ServerInstallDir);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm confused. I've got a Silverlight project that currently runs and displays a list
When reading our configuration and resource files, our .Net system currently just does ConfigurationManager.AppSettings[keyToFind]
In a system I am currently working on, there is one process that loads
I am working on a system on which currently linux kernel and microwindows windowing
I am running a live system that is currently serving about 20K pages a
I have a properties file which currently contains system names and ip addresses. What
I currently use a System.IO.FileSystemWatcher as part of a roll your own message queue
Currently we have a system which we paid for that pushes information into Excel
i´m currently dealing with a system where i have to track the state for
I currently have a Ruby on Rails system, and there are plans to port

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.