/// <summary> /// Adds a <see cref="SignInManager{TUser}"/> for the <see cref="IdentityBuilder.UserType"/>. /// </summary> /// <param name="builder">The current <see cref="IdentityBuilder"/> instance.</param> /// <returns>The current <see cref="IdentityBuilder"/> instance.</returns> public static IdentityBuilder AddSignInManager(this IdentityBuilder builder) { builder.AddSignInManagerDeps(); var managerType = typeof(SignInManager <>).MakeGenericType(builder.UserType); builder.Services.AddScoped(managerType); return(builder); }
/// <summary> /// Adds a <see cref="SignInManager{TUser}"/> for the <see cref="IdentityBuilder.UserType"/>. /// </summary> /// <typeparam name="TSignInManager">The type of the sign in manager to add.</typeparam> /// <param name="builder">The current <see cref="IdentityBuilder"/> instance.</param> /// <returns>The current <see cref="IdentityBuilder"/> instance.</returns> public static IdentityBuilder AddSignInManager <TSignInManager>(this IdentityBuilder builder) where TSignInManager : class { builder.AddSignInManagerDeps(); var managerType = typeof(SignInManager <>).MakeGenericType(builder.UserType); var customType = typeof(TSignInManager); if (!managerType.IsAssignableFrom(customType)) { throw new InvalidOperationException(Resources.FormatInvalidManagerType(customType.Name, "SignInManager", builder.UserType.Name)); } if (managerType != customType) { builder.Services.AddScoped(typeof(TSignInManager), services => services.GetRequiredService(managerType)); } builder.Services.AddScoped(managerType, typeof(TSignInManager)); return(builder); }
/// <summary> /// Adds a <see cref="SignInManager{TUser}"/> for the <seealso cref="IdentityBuilder.UserType"/>. /// </summary> /// <typeparam name="TSignInManager">The type of the sign in manager to add.</typeparam> /// <param name="builder">The current <see cref="IdentityBuilder"/> instance.</param> /// <returns>The current <see cref="IdentityBuilder"/> instance.</returns> public static IdentityBuilder AddSignInManager <TSignInManager>(this IdentityBuilder builder) where TSignInManager : class { builder.AddSignInManagerDeps(); var managerType = typeof(SignInManager <>).MakeGenericType(builder.UserType); var customType = typeof(TSignInManager); if (!managerType.GetTypeInfo().IsAssignableFrom(customType.GetTypeInfo())) { throw new InvalidOperationException($"Type {customType.Name} must derive from {"SignInManager"}<{builder.UserType.Name}>."); } if (managerType != customType) { builder.Services.AddScoped(typeof(TSignInManager), services => services.GetRequiredService(managerType)); } builder.Services.AddScoped(managerType, typeof(TSignInManager)); return(builder); }