public override Task OnBeginRequestAsync(ApiActionContext context) { var config = context.GetService <NacosConfig>(); context.RequestMessage.AddUrlQuery("tenant", config.Tenant); return(base.OnBeginRequestAsync(context)); }
/// <summary> /// 获取缓存key /// </summary> /// <param name="context"></param> /// <returns></returns> public Task <string> GetCacheKeyAsync(ApiActionContext context) { var method = context.ApiActionDescriptor.Member; var keyGenerator = context.GetService <IEasyCachingKeyGenerator>(); var arguments = context.ApiActionDescriptor.Arguments; var cacheKey = keyGenerator.GetCacheKey(method, arguments, this.prefix); return(Task.FromResult(cacheKey)); }
/// <summary> /// 获取缓存key /// </summary> /// <param name="context"></param> /// <returns></returns> public Task <string> GetCacheKeyAsync(ApiActionContext context) { var method = context.ApiActionDescriptor.Member; var keyGenerator = context.GetService <IEasyCachingKeyGenerator>(); var parameters = context.ApiActionDescriptor.Parameters.Select(x => x.Value).ToArray(); var cacheKey = keyGenerator.GetCacheKey(method, parameters, this.prefix); return(Task.FromResult(cacheKey)); }
public override Task BeforeRequestAsync(ApiActionContext context) { var options = context.GetService <SpiderOptions>(); var spiderService = options.Services.Where(o => o.ServiceName == this.Name).FirstOrDefault(); //注册中心 根据name获取url var requestStrategy = RequestStrategyFactory.Instance.CreateRequestStrategy(spiderService); string baseurl = requestStrategy.GetServiceIp(); context.HttpApiConfig.HttpHost = new System.Uri(baseurl); context.RequestMessage.Headers.Add("trace-microservice", Name); //context.RequestMessage.RequestUri = new System.Uri(Url.Combine(baseurl, context.RequestMessage.RequestUri.LocalPath)); return(Task.CompletedTask); }
public override Task OnBeginRequestAsync(ApiActionContext context) { if (context.Exception != null) { return(Task.CompletedTask); } try { var _loginInfo = context.GetService <IUser>(); context.RequestMessage.Headers.Add("Bearer ", _loginInfo.NickName); } catch (System.Exception) { return(Task.CompletedTask); } return(base.OnBeginRequestAsync(context)); }
// // 摘要: // 请求完成之后 // // 参数: // context: // 上下文 public override Task OnEndRequestAsync(ApiActionContext context) { var logger = context.GetService <ILogger <LogAttribute> >(); return(Task.CompletedTask); }