Skip to content

How can I access ContextData in my middleware? #5895

Answered by PascalSenn
sgabler asked this question in Q&A
Discussion options

You must be logged in to vote

@sgabler I guess i would just use a request middleware.

new ServiceCollection()
  .AddGraphQLServer()|
  ....
  .UseRequest< RequestTrackerMiddleware>() 
  .UseDefaultPipeline()
      public RequestTrackerMiddleware(RequestDelegate next, ITransmitter<ApiTrackerEvent> eventDataTransmitter)
      {
          _next = next;
          _eventDataTransmitter = eventDataTransmitter;
      }

      public async ValueTask InvokeAsync(IRequestContext context)
      {
          // We execute the operation first. If you need you opteration to first execute you need to register the middlewars manually
          await _next(context);
          context.Request.Body.Seek(0, SeekOrigin.Begin);
          await

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sgabler
Comment options

Answer selected by sgabler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants