title: Lumen Dependency Injection
body: <p>As the last comment of <a href="https://laracasts.com/discuss/channels/general-discussion/register-middleware-via-service-provider/?page=2" rel="nofollow">this post</a> it states the following:</p>
  
  <blockquote>
    <p>You can easily do it in any service provider (boot would be a nice place since we can use method based DI).</p>
  </blockquote>
  
  <pre><code>public function boot(\Illuminate\Contracts\Http\Kernel $kernel) {
   $kernel-&gt;appendMiddleware('Sheepy85\L5Localization\Middleware\Localization'); // prependMiddleware works too.
  }
  </code></pre>
  
  <p>This is Laravel Code for injecting a middleware from a Service Provider.</p>
  
  <p>I am trying to achieve the same thing from <em>Lumen Framework</em>, here's the code:</p>
  
  <pre><code>&lt;?php namespace Acme\Slz\Providers;
  
  use Illuminate\Contracts\Http\Kernel;
  use Illuminate\Support\ServiceProvider;
  
  class SlzServiceProvider extends ServiceProvider
  {
      /**
       * Bootstrap any application services.
       * @param Kernel $kernel
       * @return void
       */
      public function boot(Kernel $kernel)
      {
          // push the serializer middleware to the stack
          $kernel-&gt;pushMiddleware(Acme\Slz\Middleware\Serializer::class);
      }
  
      /**
       * Register any application services.
       * This service provider is a great spot to register your various container
       * bindings with the application. As you can see, we are registering our
       * @return void
       */
      public function register()
      {
      }
  }
  </code></pre>
  
  <p>But this raise the following error:</p>
  
  <pre><code>lumen.ERROR: exception 'ErrorException' with message 'Argument 1 passed to Acme\Slz\Providers\SlzServiceProvider::boot() must be an instance of Illuminate\Contracts\Http\Kernel, none given
  </code></pre>
  
  <p>Are there some more stuffs to do to enable the Dependency Container with Lumen ?</p>