title: Get session service using IServiceProvider
body: <p>I need to access session variable in ConfigureService method in ASP.NET Core 1.0 using IServiceProvider.</p>
  
  <p>I have a service that is initialized with delegate/lambda expression that can return value from any place. In this context this lambda expression argument should return value from session once called.</p>
  
  <p>Here is example code:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
  
       services.AddTransient&lt;IMyService&gt;(serviceProvider =&gt;
              {
                  return new MyService(() =&gt; {
                          var session = serviceProvider.GetServices&lt;Microsoft.AspNetCore.Session.DistributedSession&gt;().First();
                          return session.GetString("CompanyID");
                      }
                  );
              }
  
        );
  
        // Add framework services.
        services.AddMvc();
        services.AddDistributedMemoryCache();
        services.AddSession();
  }
  </code></pre>
  
  <p>My session is configured fine (I can get/set values in controllers). However, I cannot fetch the service from IServiceProvider. I cannot find what type should be provided to GetServices method to get a service that will find session.</p>