title: AspNetCore unable to resolve service
body: <p>I'm adding Microsoft.AspNetCore.Identity to a project, and I get</p>
  
  <blockquote>
    <p>InvalidOperationException: Unable to resolve service for type &#x27;Microsoft.AspNetCore.Identity.SignInManager'1[Web.Security.Entities.IUser'1[System.Int32]]&#x27; while attempting to activate &#x27;Web.Security.Services.SecurityService'2[Web.Security.Entities.IUser'1[System.Int32],System.Int32]&#x27;.</p>
  </blockquote>
  
  <p>Exception is copypasted from postman, it encoded some symbols.
  Here's my Startup.cs:</p>
  
  <pre><code>public class Startup
  {
      ServiceProvider serviceProvider;
      IConfigurationRoot configurationRoot;
      public IConfiguration Configuration { get; }
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
  
          configurationRoot = new ConfigurationBuilder()
              .AddJsonFile("appsettings.json", optional: false)
              .AddIniFile("3CXPhoneSystem.ini")
              .Build();
      }
      // This method gets called by the runtime. Use this method to add services to the container.
      // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
      public void ConfigureServices(IServiceCollection services)
      {
          serviceProvider = services
                    .AddLogging((builder) =&gt; builder.SetMinimumLevel(LogLevel.Trace))            
             .AddSingleton&lt;ISecurityService, SecurityService&lt;IUser&lt;int&gt;, int&gt;&gt;()
                   .AddSingleton&lt;ITaskService, TaskService&gt;()
                   .AddTransient&lt;IEmailSender, EmailSender&gt;()
                   .AddSingleton&lt;ITranslation, Translation&gt;()
             .BuildServiceProvider();
          services.AddDbContext&lt;SecurityDbContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString("dataContext")));
  
          services.AddIdentity&lt;Web.Security.Entities.User&lt;int&gt;, IdentityRole&gt;()
          .AddEntityFrameworkStores&lt;SecurityDbContext&gt;()
          .AddDefaultTokenProviders();
  
          services.AddCors(o =&gt; o.AddPolicy("CorsPolicy", builder =&gt;
          {
              builder
              .AllowAnyMethod()
              .AllowAnyHeader()
              .WithOrigins("http://localhost:52170");
          }));
          services.AddMvc();
  
          services.Configure&lt;IdentityOptions&gt;(options =&gt;
          {
              // Password settings
              options.Password.RequireDigit = true;
              options.Password.RequiredLength = 8;
              options.Password.RequireNonAlphanumeric = false;
              options.Password.RequireUppercase = true;
              options.Password.RequireLowercase = false;
              options.Password.RequiredUniqueChars = 6;
  
              // Lockout settings
              options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
              options.Lockout.MaxFailedAccessAttempts = 10;
              options.Lockout.AllowedForNewUsers = true;
  
              // User settings
              options.User.RequireUniqueEmail = true;
          });
  
  
      }
  
  
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          app.UseDefaultFiles();
          app.UseStaticFiles();
  
          app.Use(async (context, next) =&gt;
          {
              await next();
  
              if (context.Response.StatusCode == 404 &amp;&amp; !Path.HasExtension(context.Request.Path.Value) &amp;&amp; !context.Request.Path.Value.StartsWith("api"))
              {
                  context.Response.Redirect("/");
              }
          });
  
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(name: "DefaultApi", template: "api/{controller}/{action}/{id?}");
              routes.MapRoute("RouteToAngular", "{*url}", defaults: new { controller = "Route", action = "Index" });
  
          });
  
          app.UseAuthentication();
  
          app.UseCors("CorsPolicy");
      }
  </code></pre>
  
  <p>Here, SecurityService is a class that will handle registration/login/other identity related requests, it looks like this</p>
  
  <pre><code>public class SecurityService&lt;TUser, TKey&gt; : ISecurityService where TUser : class, IUser&lt;TKey&gt;
  {
      SignInManager&lt;TUser&gt; signInManager;
      IConfiguration configuration;
      private readonly IHttpContextAccessor httpContextAccessor;
      UserManager&lt;TUser&gt; userManager;
      IEmailSender emailSender;
      IUrlHelper urlHelper;
      ISession session;
      ILogger&lt;SecurityService&lt;TUser, TKey&gt;&gt; logger;
      ITranslation translation; 
  
      public SecurityService(
          SignInManager&lt;TUser&gt; signInManager,
          UserManager&lt;TUser&gt; userManager,
          IConfiguration configuration,
          IHttpContextAccessor httpContextAccessor,
          IEmailSender emailSender,
          IUrlHelper urlHelper,
          ISession session,
          ILogger&lt;SecurityService&lt;TUser, TKey&gt;&gt; logger,
          ITranslation translation)
      {
          this.signInManager = signInManager;
          this.userManager = userManager;
          this.configuration = configuration;
          this.httpContextAccessor = httpContextAccessor;
          this.urlHelper = urlHelper;
          this.session = session;
          this.logger = logger;
          this.translation = translation;
          this.emailSender = emailSender;
      }
  </code></pre>
  
  <p>IUser.cs: </p>
  
  <pre><code>public interface IUser&lt;TKey&gt;
  {
      TKey Id { get; set; }
      string UserName { get; set; }
      string Email { get; set; }
      bool EmailConfirmed { get; set; }
  }
  </code></pre>