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

How to inject HttpClient in the constructor of a Blazor page

$
0
0

So in our initial page we had

@inject HttpClient Http

at the top of the page and all was fine. We are now moving our code blocks into code behind to seperate the code from the page. If I remove the above line from the page and then in the code behind do:

 [Inject] public required HttpClient Http { get; set; }

all still works fine. However, we would prefer to have it in the constructor:

private HttpClient Http;public myclass (HttpClient http){    Http = http;}

where and how should I reference HttpClient so that I can use it in the above way?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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