using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using TakeoutSaaS.Module.Authorization.Policies;

namespace TakeoutSaaS.Module.Authorization.Extensions;

/// <summary>
/// 权限授权注入扩展
/// </summary>
public static class AuthorizationServiceCollectionExtensions
{
    /// <summary>
    /// 启用自定义权限策略提供者与处理器
    /// </summary>
    public static IServiceCollection AddPermissionAuthorization(this IServiceCollection services)
    {
        services.AddSingleton<IAuthorizationPolicyProvider, PermissionAuthorizationPolicyProvider>();
        services.AddScoped<IAuthorizationHandler, PermissionAuthorizationHandler>();
        return services;
    }
}
