title: Dependency Injection Unity - Conditional Resolving
body: <p>Conditional resolving is the last thing I don't understand at the moment.</p>
  
  <p>Lets say we have an interface <code>IAuthenticate</code>:</p>
  
  <pre><code>public interface IAuthenticate{
      bool Login(string user, string pass);
  }
  </code></pre>
  
  <p>Now I have two types of authentication.</p>
  
  <p><strong>Twitter auth</strong></p>
  
  <pre><code>public class TwitterAuth : IAuthenticate
  {
    bool Login(string user, string pass)
  {
     //connect to twitter api
  }
  
  }
  </code></pre>
  
  <p><strong>Facebook Auth</strong></p>
  
  <pre><code>public class FacebookAuth: IAuthenticate
  {
    bool Login(string user, string pass)
  {
     //connect to fb api
  }
  
  }
  </code></pre>
  
  <p>Registering types in unity config:</p>
  
  <pre><code>unityContainer.RegisterType&lt;IAuthenticate, TwitterAuth&gt;();
  unityContainer.RegisterType&lt;IAuthenticate, FacebookAuth&gt;();
  </code></pre>
  
  <p>inject objects via DI in our controller:</p>
  
  <pre><code>private readonly IAuthenticate _authenticate;
  
  public AuthenticateController(IAuthenticate authenticate)
  {
      _authenticate = authenticate;
  }
  
  
  
  // login with twitter
  public virtual ActionResult Twitter(string user, string pass)
  {
      bool success =
              _authenticate.Login(user, pass);
  }
  
  
  
  // login with fb
  public virtual ActionResult Facebook(string user, string pass)
  {
      bool success =
              _authenticate.Login(user, pass);
  }
  
  
  
  // login with google
  public virtual ActionResult Google(string user, string pass)
  {
      bool success =
              _authenticate.Login(user, pass);
  }
  </code></pre>
  
  <p>How exactly will unity know which object does it have to resolve for different types of authentication? How do I do conditional resolving in this case?</p>
  
  <p>I spoke with friend of mine, and he explained if this situation appears it is wrong design, but this is just factory pattern used.</p>