title: Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory`1
body: <p><a href="https://i.stack.imgur.com/YNK53.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/YNK53.jpg" alt="enter image description here" /></a></p>
  <p>This error occurs while trying to add-migration for the first time. I have added the extension method and my service class</p>
  <p>public void ConfigureServices(IServiceCollection services)
  {</p>
  <pre><code>        services.AddCors();
          services.AddControllers();
          
          services.Configure&lt;AppSettings&gt;(AppSettings);
          services.ConfigureJWT(Configuration);
          services.ConfigureIdentity();
          services.AddScoped&lt;ILoginService, LoginService&gt;();
          services.AddScoped&lt;IUserClaimsPrincipalFactory&lt;ApplicationUser&gt;, CustomClaimPrincipalFactory&gt;();
      }
  </code></pre>
  <p>public static void ConfigureIdentity(this IServiceCollection services)
  {</p>
  <pre><code>        var builder = services.AddIdentityCore&lt;ApplicationUser&gt;(o =&gt;
          {
              o.Password.RequireDigit = true;
              o.Password.RequireLowercase = false;
              o.Password.RequireUppercase = false;
              o.Password.RequireNonAlphanumeric = false;
              o.Password.RequiredLength = 6;
              o.User.RequireUniqueEmail = true;
          });
          builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole),
         builder.Services);
          builder.AddEntityFrameworkStores&lt;AuthDBContext&gt;()
          .AddDefaultTokenProviders();
  
  
      }
  </code></pre>
  <p>public class CustomClaimPrincipalFactory : UserClaimsPrincipalFactory&lt;ApplicationUser, IdentityRole&gt;
  {</p>
  <pre><code>    public CustomClaimPrincipalFactory(
          UserManager&lt;ApplicationUser&gt; userManager,
          RoleManager&lt;IdentityRole&gt; roleManager,
          IOptions&lt;IdentityOptions&gt; optionsAccessor)
          : base(userManager, roleManager, optionsAccessor)
      {
      }
  
      protected override async Task&lt;ClaimsIdentity&gt; GenerateClaimsAsync(ApplicationUser user)
      {
          ClaimsIdentity identity = await base.GenerateClaimsAsync(user);
          identity.AddClaim(new Claim(&quot;ServiceSite&quot;, user.ServiceSite ?? &quot;&quot;));
          return identity;
      }
  }
  </code></pre>
  <p>Here is the Error again</p>
  <p>An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory<code>1[AuthenticationService.Entities.ApplicationUser] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory</code>1[AuthenticationService.Entities.ApplicationUser]': Unable to resolve service for type 'AuthenticationService.Data.AuthDBContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<code>9[AuthenticationService.Entities.ApplicationUser,Microsoft.AspNetCore.Identity.IdentityRole,AuthenticationService.Data.AuthDBContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserClaim</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserRole<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserLogin</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserToken<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim</code>1[System.String]]'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.UserManager<code>1[AuthenticationService.Entities.ApplicationUser] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.UserManager</code>1[AuthenticationService.Entities.ApplicationUser]': Unable to resolve service for type 'AuthenticationService.Data.AuthDBContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<code>9[AuthenticationService.Entities.ApplicationUser,Microsoft.AspNetCore.Identity.IdentityRole,AuthenticationService.Data.AuthDBContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserClaim</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserRole<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserLogin</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserToken<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim</code>1[System.String]]'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.IUserStore<code>1[AuthenticationService.Entities.ApplicationUser] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore</code>9[AuthenticationService.Entities.ApplicationUser,Microsoft.AspNetCore.Identity.IdentityRole,AuthenticationService.Data.AuthDBContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserClaim<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserRole</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserLogin<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserToken</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim<code>1[System.String]]': Unable to resolve service for type 'AuthenticationService.Data.AuthDBContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore</code>9[AuthenticationService.Entities.ApplicationUser,Microsoft.AspNetCore.Identity.IdentityRole,AuthenticationService.Data.AuthDBContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserClaim<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserRole</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserLogin<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserToken</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim<code>1[System.String]]'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.IRoleStore</code>1[Microsoft.AspNetCore.Identity.IdentityRole] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore<code>5[Microsoft.AspNetCore.Identity.IdentityRole,AuthenticationService.Data.AuthDBContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserRole</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim<code>1[System.String]]': Unable to resolve service for type 'AuthenticationService.Data.AuthDBContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore</code>5[Microsoft.AspNetCore.Identity.IdentityRole,AuthenticationService.Data.AuthDBContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserRole<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim</code>1[System.String]]'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory<code>1[AuthenticationService.Entities.ApplicationUser] Lifetime: Scoped ImplementationType: AuthenticationService.Common.CustomClaimPrincipalFactory': Unable to resolve service for type 'AuthenticationService.Data.AuthDBContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore</code>9[AuthenticationService.Entities.ApplicationUser,Microsoft.AspNetCore.Identity.IdentityRole,AuthenticationService.Data.AuthDBContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserClaim<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserRole</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserLogin<code>1[System.String],Microsoft.AspNetCore.Identity.IdentityUserToken</code>1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim`1[System.String]]'.)</p>