authenticationasp.net-core-middlewarehotchocolateaspnetcore-environment

Using app.Environment in HttpRequestInterceptor?


In Program.cs I can use

app.Environment.IsDevelopment()

Now I have a custom HttpRequestInterceptor : DefaultHttpRequestInterceptor with a method

public override ValueTask OnCreateAsync(HttpContext context,
IRequestExecutor requestExecutor, IQueryRequestBuilder requestBuilder,
CancellationToken cancellationToken)

How can I get access to app.Environment.IsDevelopment() in that method? (I want to set some kind of faked authentication during development)


Solution

  • You can inject the IWebHostEnvironment through the constructor of the HttpRequestInterceptor and perform your IsDevelopment check on that injected instance.