title: How to Initialize Generic Type in other class
body: <p>Hi I am working on a generic solution where I am extending <code>System.Security.Principal.IIdentity</code> to add some more user Information. This component will be used in different solution again The user information will come from different sources like DB or Active Directory or even XML files. I have make some solution where an <code>IIdentityInitializer</code> will Initialize <code>IIdentity</code> and I will have different class implementing these interface.</p>
  
  <pre><code>public interface IIdentityInitializer&lt;T&gt;
  where T:IIdentity
  {
      T Initialize(string userid, string password)
  }
  public ActiveDirectoryIdentityInitializer&lt;T&gt; :IIdentityInitializer&lt;T&gt;
  where T:IIdentity
  {
      public T Initialize(string username, string password)
      {
          //Load Logic and assign data from Active directory to different property of T
      }
  }
  
  public DBIdentityInitializer&lt;T&gt;:IIdentityInitializer&lt;T&gt;
  where T:IIdentity
  {
      public T Initialize(string username, string password)
      {
          //Load Logic and assign data from DB to different property of T
      }
  }
  
  public CustomIdentity1:IIdentity
  {
      public string Name{get;set}
      public string EMail{get;set;}
      public CustomIdentity1(IIdentityInitializer&lt;CustomIdentity1&gt; ci){}
  }
  
  public CustomIdentity2:IIdentity
  {
      public string Name{get;set}
      public string EMail{get;set;}
      public string Mobile{get;set;}
      public string EmployeeId{get;set;}
      public CustomIdentity2(IIdentityInitializer&lt;CustomIdentity2&gt; ci){}
  }
  </code></pre>
  
  <p>Now I have <code>ActiveDirectoryInitializer</code> and <code>DBInitializer</code> with <code>CustomIdentity1</code> and <code>CustomIdentity2</code> I have to know the Logic in Initialize that can work with in a generic way cause in future we can have more type of <code>IIdentity</code> and <code>IIdentityInitializer</code>.</p>