title: Laravel Bind Object Interface with an implementation that has variables parameters in it's constructor
body: <p>Please note that before aksing this questions I've looked into:</p>
  
  <p><a href="https://stackoverflow.com/questions/15483542/laravel-4-way-to-inject-an-object-that-requires-configuration-into-a-controller">laravel-4 way to inject an object that requires configuration into a controller</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15595760/laravel-4-passing-data-from-make-to-the-service-provider">Laravel 4: Passing data from make to the service provider</a></p>
  
  <p>and </p>
  
  <p><a href="https://stackoverflow.com/questions/21680795/laravel-4-confused-about-how-to-use-appmake">Laravel 4: Confused about how to use App::make()</a></p>
  
  <p>But I cannot see that they answer my question!</p>
  
  <p>Domain Model:
  A Site must have an Owner and currently this owner is of type Customer but can change in the future to be a Reseller or an Employee etc.. so I'm using Polymorphism as follows:</p>
  
  <p>class Site has an Owner Property.
  Owner is an interface,
  Customer is a class which implements Owner,
  Customer has a Name and a Uid therefore these are required in the constructor of Customer.</p>
  
  <p>Now I want to bind the Customer implementation to the Owner interface so that whenever I call Owner I get a Customer.</p>
  
  <p>We would normally do this:</p>
  
  <pre><code>class UseCustomerAsSiteOwnerServiceProvider extends ServiceProvider{
  
      public function register()
      {
          $this-&gt;app-&gt;bind('hidden\Domain\Model\Site\Owner', function ($app)
          {
              return $this-&gt;app-&gt;make(new Customer());
          });
  
  
      }
  
  }
  </code></pre>
  
  <p>However Customer() requires $id and $name to be initialized and these are variable objects -  not static so I don't know how to pass them?</p>
  
  <p>I tried this:</p>
  
  <pre><code>public function register()
      {
          $this-&gt;app-&gt;bind('hidden\Domain\Model\Site\Owner', function ($app) use ($id, $name)
          {
              return $this-&gt;app-&gt;make(new Customer($id, $name));
          });
  
  
      }
  </code></pre>
  
  <p>But in this case the $name and $id in the USE statement are not defined. Anyone has ideas?</p>
  
  <p>UPDATE:
  The Customer Constructor is as follows:</p>
  
  <pre><code>    /**
       * Initialise a new Customer
       *
       * @param Identifier $id
       * @param CustomerName $name
       */
      public function __construct(Identifier $id, $name)
      {
          $this-&gt;id       =       $this-&gt;setId($id);
          $this-&gt;name     =       $this-&gt;setName($name);
      }
  </code></pre>
  
  <p>This will be initialized from an Aggregate root (Site). The correct types will be passed to it.</p>