title: How to use New() operator with parameters in a Generic class
body: <p>Iam trying to make a <code>generic class</code> that <strong>receives a Type</strong>.
  this <code>generic class</code> will need to create an instance from the received type.
  The received type has two overloads in his constructor, <strong>one constructor can receive a parameter</strong> but <strong>the other one doesn't have any parameter</strong>.
  y generic class need sometimes to create object from received class without parameters in constructor and other times with parameter in constructor.</p>
  <p>A simple view in my generic class :</p>
  <pre><code>public sealed class Repo&lt;TContext&gt; : IRepo&lt;TContext&gt;, IDisposable
      where TContext : DbContext, new()
  {
      #region properties
  
      /// &lt;summary&gt;
      /// Private DBContext property
      /// &lt;/summary&gt;
      private DbContext _Context { get; } = null;
  
  
      /// &lt;summary&gt;
      /// Determine if Lazy Loading either activate or not
      /// &lt;/summary&gt;
      private bool _LazyLoaded { get; set; }
  
      #endregion
  
      #region Construcors
  
      public Repo(bool LazyLoaded)
      {
          _Context                                  = new TContext();
          _LazyLoaded                               = LazyLoaded;
          _Context.ChangeTracker.LazyLoadingEnabled = LazyLoaded;
      }
  
      public Repo(DbContext context,bool LazyLoaded)
      {
          _Context                                  = context;
          _LazyLoaded                               = LazyLoaded;
          _Context.ChangeTracker.LazyLoadingEnabled = LazyLoaded;
      }
  </code></pre>
  <p>at now everything's good, but when I add a third constructor in my <code>generic clas</code>s for creating an instance from received <code>TContext</code> but this time with his (<code>TContext</code>) constructor that need one parameter,</p>
  <pre><code>public Repo(DbContextOptionsBuilder&lt;TContext&gt; optionsBuilder,bool LazyLoaded)
  {
      _Context                                  = new TContext(optionsBuilder);
      _LazyLoaded                               = LazyLoaded;
      _Context.ChangeTracker.LazyLoadingEnabled = LazyLoaded;
  }
  </code></pre>
  <p><strong>I got this error:</strong></p>
  <blockquote>
  <p>Error  CS0417  'TContext': cannot provide arguments when creating an instance of a variable type   MyTypeName</p>
  </blockquote>
  <p><strong>The Question:</strong></p>
  <p>My question is <strong>how I can create an instance from <code>TContext</code> using his constructor that receive parameters ?</strong></p>
  <p>thank you in advance.</p>