is there a way to inject let say httpClient into my own custom class?
Just to be clear - i known how to use DI in blazor injecting into components or other services. Just for testing its possibility.
i want to do something like just in code
protected override async Task OnInitializedAsync()
{
GSP gsp = new GSP("db1","table1");
gsp.get("users", ()=>{ do something with data}); // and this should call api and get users
}
so i have
public class GSP
{
[Inject]
public HttpClient httpClient { get; set; }
...
}
but it is null
i checked also ctor option
public GSP(HttpClient httpClient)
{
this.httpClient = httpClient;
}
but then i have to pass this httpClient manualy that was injected into component for example.
i can do
private HttpClient httpClient = new HttpClient { BaseAddress }
but then i have no BaseAdres. and heare we go again - easier way to get this BaseAddres in this place ? ;)
is it possible? or it is just 'bad practise' thats why i canot find that? thanks a lot !
question from:https://stackoverflow.com/questions/65901915/blazor-wasm-how-to-inject-from-di-into-custom-class