Service Provider Question
I have a Blazor WASM intranet site with a backend API. I would like to have a really easy way of switching between dev/test/production api, where both the URI and the Name can be utilized in blazor.
I created an APIConnection class, which has three classes that implement for each of dev/test/production (1st screenshot).
Then I have added that class to service provider (2nd sceenshot). I can easily change the name of the class when I need to switch.
However, I'm having difficulty using that scoped instance to send the URI to the HttpClient. How do I access the scoped instance of the APIConnection inside the scoped instance of HttpClient (3rd sceenshot)?



9 Replies
Your
ApiConnectionX
instances dont need to be scoped, they have no state at allMainly I'd like to show the name somewhere on the blazor pages, so the user knows which api is being used.
they can safely be
Singleton
instead, and you'd use it by simply putting an IAPIConnection connection
or similar in your constructor of Client
I guess I'm not sure how to access it from within the lambda for the httpclient
Regardless scoped or singleton, if that makes sense
modify
Client
you'd need to take in either the API connection (recommended) or a serviceprovider reference into Client
itself
since thats what you have access to in the lambdaOkay, thank you. I'll give that a try
Please no image from $code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/This worked! Thank you for the help 🙂