Suchiman / BlazorDualMode

Demo on how to run dynamically in client or server side mode
MIT License
145 stars 24 forks source link

if I activate the http through a class and I think a centralized service does not work in the server model #1

Closed carlosalcantara2668 closed 5 years ago

carlosalcantara2668 commented 5 years ago

I did a service to centralize the http, but when changing from the client model to the server, it simply does not work.

image

image

image

Suchiman commented 5 years ago

"does not work" isn't an appropriate error description. Any exceptions? What do you see that makes you think it doesn't work? Did you take care of step 2 of the howto? Be extra careful to register the HttpClient inside the Startup.cs of the Client Project: https://github.com/Suchiman/BlazorDualMode/blob/853b2ec3d4b3ac028c365d593265e932912f02ff/BlazorDualMode.Client/Startup.cs

carlosalcantara2668 commented 5 years ago

if you register it, if you perform the exercise of creating a service to center http calls and change to the server model, it simply does not respond.

if the call is direct within the page if you are working very well in the server model.

Please try to make the call of the http on the FetchData page through a registered service.

image

carlosalcantara2668 commented 5 years ago

Please forgive my writing in English. that I am new studying the language.

Suchiman commented 5 years ago

@carlosalcantara2668 i see, try using AddScoped instead of AddSingleton, that works for me. The reason is that Blazors IUriHelper is a Scoped service hence HttpClient must be scoped and so does ServiceArticulo. The problem is that a singleton service (longer lifetime) cannot resolve a scoped service (shorter lifetime).

carlosalcantara2668 commented 5 years ago

@Suchiman now it's working, this is perfect, thank you very much.