title: Create Instance of a class from interface which it implements
body: <p>Hi I am trying to build a generic UoWFactory which creates a UnitOfWork(there will be one default unitofwork and multiple custom implementaitons as well). So far I was able to create factory method which creates default UoW and returns it. I have modify the following method to return specified UoW depending on the parameter passed.</p>
  
  <p>Current implementation</p>
  
  <pre><code>private BaseResult&lt;IUnitOfWork&gt; GetUnitOfWorkByCompiledModel&lt;IUnitOfWork&gt;(DbCompiledModel compiledModel)
  {
      return new BaseResult&lt;IUnitOfWork&gt;
      {
          Payload = new DbUnitOfWork(_context, _dbRepository, _mapper, _entityMapper)
      };
  }
  </code></pre>
  
  <p>I wish to have something like this</p>
  
  <pre><code>private BaseResult&lt;TUoW&gt; GetUnitOfWorkByCompiledModel&lt;IUnitOfWork&gt;(DbCompiledModel compiledModel) where TUoW :Class
  {
      return new BaseResult&lt;TUoW&gt;
      {
          //Create instance of type TUoW where TUoW can be IUnitOfWork, ICustomUnitOfWork etc
          //DbUnitOfWork implements IUnitOfWork and CustomUnitOfWork implements ICustomUnitOfWork
          //All the TUoW will have constructors with identical parmeters
      };
  }
  </code></pre>
  
  <p>Create an instance of class is straight forward</p>
  
  <pre><code>Activator.CreateInstance (Type type, object[] args);
  </code></pre>
  
  <p>But if I pass Interface type as a parameter how to create instance of DbUnitOfWork or CustomUnitOfWork.
  eg:-</p>
  
  <pre><code>GetUnitOfWorkByCompiledModel&lt;IUnitOfWork&gt;(compiledModel);
  GetUnitOfWorkByCompiledModel&lt;ICustomUnitOfWork&gt;(compiledModel);
  </code></pre>