Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

.NET 8 Blazor Cascading Parameter HttpContext vs HttpContextAccessor.HttpContext

$
0
0

With the following code in a standard Blazor Web Application in program.cs,

builder.Services.AddRazorComponents();

The underlying framework will create a cascading parameter for HttpContext, which can be used in your components as such:

[CascadingParameter]HttpContext? HttpContext { get; set; }

Separately, you can inject IHttpContextAccessor into your components. In your profram.cs, you'd do something like:

builder.Services.AddHttpContextAccessor();

And in your component you'd do something like

@inject IHttpContextAccessor httpCtxAccessor

However, httpCtxAccessor.HttContext does NOT equal the cascading parameter HttpContext.Apparently, these are very different things, yet the designers of Blazor thought it made sense to refer to both as HttpContext.

Is there a more sensible way to think about (and perhaps name) these items?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>