/// <summary> /// 路由注册 /// </summary> /// <param name="pathTemplate">路径</param> /// <param name="dispatcher">处理器</param> public void Add(string pathTemplate, ILayIMDispatcher dispatcher) { Error.ThrowIfNull(pathTemplate, nameof(pathTemplate)); Error.ThrowIfNull(dispatcher, nameof(dispatcher)); dispatchers.Add(new Tuple <string, ILayIMDispatcher>(pathTemplate, dispatcher)); }
public async Task Dispatch(ILayIMDispatcher dispatcher, HttpContext context) { string currentUserId = GetCurrentUserId(context); if (string.IsNullOrEmpty(currentUserId)) { context.Response.ContentType = "application/json;charset=utf-8;"; context.Response.StatusCode = StatusCodes.Status401Unauthorized; await context.Response.WriteAsync(JsonUtil.ToJSON(LayIMCommonResult.Error("Unauthorized"))); return; } //save current user id in http context context.Items.TryAdd(LayIMGlobal.USER_KEY, currentUserId); await dispatcher.Dispatch(context); }