title: C# Unity how to resolve a class which already has got injections using factory method
body: <p>I have two implementation of an interface. Eg; I have an interface named IWriter. And two implementation such as FileWriter (which writes to a folder) and FTPWriter which uploads file to FTP. I would like to resolve based on a config setting. so need to use a factory method. Both FileWriter and FTPWriter has got some interfaces injected in their constructors. So how do i resolve this?</p>
  
  <pre><code>public interface IWriter{ void Write();}
  public class FileWriter : IWriter{
      public FileWriter(IInterface interface1, IInterface 2)
      {
  
      }
  }
  
  public class FTPWriter : IWriter{
      public FTPWriter(IInterface interface1, IInterface 2)
      {
  
      }
  }
  
  public static Factory
  {
      public IWriter GetWriter(string mode)
      {
          if(mode=="1")
              return new FileWriter();//But i need the object to the interface1, interface2 injected
          else
              return new FTPWriter(); //But i need the object to the interface1, interface2 injected
  
      }
  }
  
  public class MainService : IMainService{
       public MainClass(IOtherInterface other, IWriter writer){
  
       }
  }
  </code></pre>
  
  <p>My unity config:</p>
  
  <pre><code>container.RegisterType&lt;IMainService, MainService &gt;();
  </code></pre>
  
  <p>Thanks</p>