public async Task Invoke(HttpContext context, IRequestRepo requestRepo, IAuxUserAgentService userAgentService) { //getting user agent from header StringValues user_agent = ""; context.Request.Headers.TryGetValue("User-Agent", out user_agent); //waiting for user agent // var result = await userAgentService.ParseUserAgentData(user_agent.ToString()); //saving request(request+useragentdata) data to dbcontext requestRepo.Add(new Request { Source = context.Connection.RemoteIpAddress.ToString() + ":" + context.Connection.RemotePort.ToString(), Destination = context.Request.Path.ToString(), Method = context.Request.Method, //UserAgent = result, }); //save changes to db await requestRepo.SaveChangesAsync(); //calling next to go to next middleware await _next(context); }