title: How to use DI in Model (or VM)?
body: <p>I had tried to separate DAL and inject it to DI in Program.cs like below</p>
  <pre><code>services.AddScoped&lt;IDataLoadServices, DataLoadServices&gt;(); 
  </code></pre>
  <p>Then to get data from DB and put it into Model (maybe can call it ViewModel) I need to get these services from the constructor of Model class like below</p>
  <pre><code>class MyModel{
      public IList Countries{get;set;}
      
      public int SelectedCountryCode{get;set;
      
      //default Ctor
      //call When creating by Model Binding
      public MyModel(){
        
      }
      //call when creating by Factory
      [ActivatorUtilitiesConstructor]
      public MyModel(IDataLoadServices ser){
           Countries = ser.LoadMyListFromDB();           
      }
  }
  </code></pre>
  <p>In Controller Action I can create a MyModel instance by using FactoryServices.(not shown here)
  after that passing to View successfully.</p>
  <pre><code>@model MyModel
  &lt;form method=&quot;post&quot; asp-controller=&quot;MyController&quot;&gt;
    ...
    &lt;select asp-for=&quot;SelectedCountryCode&quot; asp-items=&quot;@(new SelectList(Model.Countries, &quot;CountryCode&quot;, &quot;CountryName&quot;))&quot;&gt;            
    &lt;/select&gt;
    &lt;input type=&quot;hidden&quot; asp-for=&quot;SelectedCountryCode&quot; /&gt;
   ...
  </code></pre>
  <p>In Controller Action for post-Submit</p>
  <pre><code>[HttpsPost]
  public IActionResult Submited(MyModel model){
     //model.Countries == null
     //model.SelectedCountryCode == 0 ????
  }
  </code></pre>
  <p>The problem I think that is MyModel was created in Model Binding Stage with Default Contructor so that It cant get Countries list and somehow can't resolve SelectedCountryCode.</p>
  <ol>
  <li>Is that Right ?</li>
  <li>Any idea for bypassing this problem ?</li>
  </ol>