コード例 #1
0
        public static T GetValue <T>(this IAppContext context, string key)
        {
            var val = context?.GetValue(key);

            if (val is null)
            {
                return(default);
コード例 #2
0
        public async override Task Invoke(AspectContext context, AspectDelegate next)
        {
            string      functionCode = context.ImplementationMethod.GetFunctionCode();
            IAppContext appContext   = context.ServiceProvider.GetRequiredService <IAppContext>();
            string      contextValue = appContext.GetValue(ContextKey)?.ToString();
            var         throttleCode = new ThrottleCode
            {
                ContextKind  = ContextKey,
                FunctionCode = functionCode,
                ContextValue = contextValue
            };
            var throttleValue = new ThrottleValue();

            var throttleService = context.ServiceProvider.GetRequiredService <IThrottleService>();

            if (await throttleService.ShouldPass(throttleCode, throttleValue))
            {
                await next.Invoke(context);
            }
            else
            {
                throw new ApplicationException("Throttle limited.");
            }
        }
コード例 #3
0
 public static string UserId(this IAppContext appContext)
 {
     return(appContext.GetValue <string>(nameof(AppContextKeys.UserId)));
 }
コード例 #4
0
 public static string RequestIp(this IAppContext appContext)
 {
     return(appContext.GetValue <string>(nameof(AppContextKeys.RequestIp)));
 }
コード例 #5
0
 public static IList <string> LogicRoleIds(this IAppContext appContext)
 {
     return(appContext.GetValue <IList <string> >(nameof(AppContextKeys.LogicRoleIds)));
 }
コード例 #6
0
 public static bool IsAuthenticated(this IAppContext appContext)
 {
     return(appContext.GetValue <bool>(nameof(AppContextKeys.IsAuthenticated)));
 }