public async Task Invoke(HttpContext context) { try { IHeaderDictionary headers = context.Request.Headers; ICookieHelper _cookieHelper = context.GetInstanceFromContext <ICookieHelper>(); IJWTHelper _JWTHelper = context.GetInstanceFromContext <IJWTHelper>(); ICryptoHelper _cryptoHelper = context.GetInstanceFromContext <ICryptoHelper>(); string cookieName = _cookieHelper.GetCookieName(); if (!_cookieHelper.isCookieDeleted(cookieName)) { string updatedToken = _JWTHelper.updateJWTToken(); string encryptedToken = _cryptoHelper.encrypt(updatedToken); _cookieHelper.UpdateCookie(encryptedToken); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { await _next.Invoke(context); } }