Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Inject service into blazor alway get null

$
0
0

In Program.cs

builder.Services.AddScoped<HttpClient>(s => {    var httpClient = new HttpClient    {        BaseAddress = new Uri("https://localhost:7273/")    };    return httpClient; });  builder.Services.AddScoped<IApiService, ApiService>();

In Home.razor.cs

[Inject]  protected IApiService? ApiService { get; set; }    protected override async Task OnInitializedAsync()  {     if (ApiService != null)     {         User = await ApiService.GetDataAsync<AuthUserModel>("/api/admin/auth");         Debug.WriteLine("OK");     }     else     {         Debug.WriteLine("ApiService is not injected");     }     await base.OnInitializedAsync();  }

Why alway recieve "ApiService is not injected" ?Thanks and regards!


Viewing all articles
Browse latest Browse all 12111

Trending Articles



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