title: asp net core requesting service in Configure method returns null
body: <p>I'm trying to get some of my services in the configure method so I can seed my database easier with them.</p>
  
  <p>So I've injected <strong>IServiceProvider</strong> in my Configure method but every time I do : <code>var service = serviceProvider.GetService&lt;UserService&gt;();</code> it returns null... </p>
  
  <p>Here's my code : </p>
  
  <pre><code>public class Startup
      {
          public Startup(IHostingEnvironment env)
          {
              var builder = new ConfigurationBuilder()
                  .SetBasePath(env.ContentRootPath)
                  .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  
              builder.AddEnvironmentVariables();
              Configuration = builder.Build();
          }
  
          public IConfigurationRoot Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container
          public void ConfigureServices(IServiceCollection services)
          {
  
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                options.UseSqlServer(this.Configuration.GetConnectionString("DbConnectionString")));
  
              // Add framework services.
              services.AddIdentity&lt;IdentityUser, IdentityRole&gt;().AddEntityFrameworkStores&lt;IdentityDbContext&gt;().AddDefaultTokenProviders();
              string connection = this.Configuration.GetConnectionString("DbConnectionString");
              services.AddEntityFramework();
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(connection));
              services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;()
                  .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
                  .AddDefaultTokenProviders();
              services.Configure&lt;AppSettings&gt;(this.Configuration.GetSection("AppSettings"));
  
              services.AddScoped&lt;IsAuthorized&gt;();
              services.AddSingleton&lt;UserManager&lt;ApplicationUser&gt;&gt;();
              services.AddTransient&lt;IUsersService, UserService&gt;();
  
              services.AddMvc(config =&gt; { config.Filters.Add(typeof(SingletonUsers)); });
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
          public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider services)
          {
              loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
              loggerFactory.AddDebug();
  
              app.UseMvc();
  
              // This returns the context.
              var context = services.GetService&lt;ApplicationDbContext&gt;();
  
              // This returns null.
              var userService = services.GetService&lt;UserService&gt;();
  
              // Can't work without the UserService
              MyDbInitializer.Initialize(context, userService);
          }
      } 
  </code></pre>