Exemple #1
0
 public MembershipClaimsService(IMembershipService membershipService, IRoleService roleService, MembershipOptions options)
 {
     this.membershipService = membershipService.ThrowIfNull(nameof(membershipService));
     this.roleService       = roleService.ThrowIfNull(nameof(roleService));
     this.options           = options.ThrowIfNull(nameof(options));
 }
        /// <summary>
        /// Register Identity Server to use a ASP.NET 2.0 Membership database to authenticate users
        /// </summary>
        /// <param name="builder">Identity Server Service builder</param>
        /// <param name="options">Identity Server Membership Options</param>
        public static IIdentityServerBuilder AddMembershipService(this IIdentityServerBuilder builder, MembershipOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.ConnectionString))
            {
                throw new ArgumentException(nameof(options.ConnectionString));
            }

            builder.Services.AddSingleton(options);

            builder.Services.AddTransient <IMembershipPasswordHasher, MembershipPasswordHasher>();

            builder.Services.AddTransient <IMembershipContext, MembershipContext>();
            builder.Services.AddTransient <IMembershipRepository, MembershipRepository>();
            builder.Services.AddTransient <IRoleRepository, RoleRepository>();

            builder.Services.AddTransient <IMembershipService, MembershipService>();
            builder.Services.AddTransient <IRoleService, RoleService>();
            builder.Services.AddTransient <IMembershipClaimsService, MembershipClaimsService>();

            builder.Services.AddTransient <IProfileService, MembershipProfileService>();

            return(builder);
        }