title: Pass object of custom settings to nested classes
body: <p>In an MVVM application I have a Manager class that is responsible for grouping all the classes that my application needs and passing them in a single object to all the ViewModels.</p>
  <p>This manager has a Menu class, a Customer class, and a settings class. In that settings class, I group all the settings that come from two sources:</p>
  <ul>
  <li>configuration of the App.Config file.</li>
  <li>configuration of environment variables from the computer.</li>
  </ul>
  <p>The case is that if for example, inside my ViewModel I use a CustomClass1 and inside it a CustomClass2 and this class need a setting, I always have to pass a Settings object first to CustomClass1 and then to CustomClass2 with the settings already defined.</p>
  <p>Is there any way to make this better?</p>
  <p>Code example:</p>
  <pre class="lang-cs prettyprint-override"><code>public class Settings {
      public string FROM_ENVIROMENT { get; }
      public string URL_OF_WEBSERVICE { get; }
  
      public Settings () {
          FROM_ENVIROMENT = Environment.GetEnvironmentVariable (&quot;ENV_1&quot;) ?? Environment.GetEnvironmentVariable (&quot;ENV_2&quot;) ?? &quot;MY_DEFAULT_ENV&quot;;
          URL_OF_WEBSERVICE = Properties.Settings.Default.URL_OF_WEBSERVICE;
      }
  }
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>public class Manager
  {    
      public Customer Customer { get; }
      public Settings Settings { get; set; }
  
      public Manager () {
          Customer = new Customer ();
          Settings = new Settings ();
      }
  }
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>public class MainViewModel{
      public Manager Manager { get; set; }
      public CustomerViewModel CustomerVM { get; set; }
  
      public MainViewModel () {
          Manager = new Manager ();
          CustomerVM = new CustomerViewModel(Manager);
      }
  }
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>public class CustomerViewModel{
      private Manager Manager { get; }
      
      public Customer Customer {
          get =&gt; Manager.Customer;
      }
      
      public Settings Settings {
          get =&gt; Manager.Settings;
      }
  
      public CustomerViewModel(Manager _manager) {
          Manager = _manager;
  
          CustomClass1 class1 = new CustomClass1(Settings);
      }
  }
  
  public class CustomClass1{
      public Settings Settings { get; }
      
      public CustomClass1(Settings _settings) {
          Settings = _settings;
      }
  
      public SomeTask(){
          CustomClass2 class2 = new CustomClass2(Settings);
      }
  }
  
  public class CustomClass2{
      public Settings Settings { get; }
      
      public CustomClass2(Settings _settings) {
          // Here, I need a Setting and the object pass from Manager, to MainViewModel, to CustomerViewModel, to CustomClass1 and finally to CustomClass2...
      }
  }
  </code></pre>