title: Laravel/Lumen bind interface on middleware based on user input
body: <p>I'm quite new to this so pls bare with me. :)</p>
  <p>I have 2 implementations of an interface, let's just name them <code>BankService1</code> and <code>BankService2</code> and both of them adheres to <code>DisbursementInterface</code>.</p>
  <p>Typically if I only need one implementation, i would just bind the interface and the implementation in <code>bootstrap/app.php</code> and inject the interface to the constructor of the controller. However, I want to dynamically bind the implementation based on user input kind of like this:</p>
  <pre class="lang-php prettyprint-override"><code>//if remittance is true, use bank 1 else bank 2
  $disbursementService = ($request['remittance'] ? 'BankService1' : 'BankService2');
  
  $this-&gt;app-&gt;bind('My\Namespace\DisbursementInterface', &quot;My\Namespace\\{$disbursementService}&quot;);
  </code></pre>
  <p>I think the middleware is the best place to do like this since i need the <code>$request</code> object. However i'm having a hard time binding the implementations because like what i said, i'm still quite new at this.</p>
  <p>Any suggestions?</p>