public static T GetValue <T>(this IAppContext context, string key) { var val = context?.GetValue(key); if (val is null) { return(default);
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."); } }
public static string UserId(this IAppContext appContext) { return(appContext.GetValue <string>(nameof(AppContextKeys.UserId))); }
public static string RequestIp(this IAppContext appContext) { return(appContext.GetValue <string>(nameof(AppContextKeys.RequestIp))); }
public static IList <string> LogicRoleIds(this IAppContext appContext) { return(appContext.GetValue <IList <string> >(nameof(AppContextKeys.LogicRoleIds))); }
public static bool IsAuthenticated(this IAppContext appContext) { return(appContext.GetValue <bool>(nameof(AppContextKeys.IsAuthenticated))); }