Comments (7)
Hi @julienGrd, I'm really surprised you were ever able to run code where you were injecting scoped services into singletons. The compiler should always have thrown an error as that shouldn't be allowed to happen.
Yes that's why i was surprise also ! but it works ! until the last preview, that's why i think they resolve a bug
In terms of your app, why do you choose to use different scoped between Blazor Server and Blazor WebAssembly? There is no difference between scoped and singleton in Blazor WebAssmebly. Hence the guidance from Microsoft to use scoped services as they will act the same between both hosting models.
OK it make sense, no problem for me to put all my services in scoped. i double check and if i put all my services scoped it work in the both modes
I really don't see a reason to change our approach on this. Our services being added to the DI container as scoped is the correct configuration. If you really want to run a non-standard configuration, then instead of using the provided
AddBlazoredLocalStorage
helper for adding services, you can just add them manually with the configuration you choose.
With passing all my service scoped, i don't have any problems, i close this issue, thanks for your help !
from localstorage.
Hi @julienGrd, I'm really surprised you were ever able to run code where you were injecting scoped services into singletons. The compiler should always have thrown an error as that shouldn't be allowed to happen.
In terms of your app, why do you choose to use different scoped between Blazor Server and Blazor WebAssembly? There is no difference between scoped and singleton in Blazor WebAssmebly. Hence the guidance from Microsoft to use scoped services as they will act the same between both hosting models.
I really don't see a reason to change our approach on this. Our services being added to the DI container as scoped is the correct configuration. If you really want to run a non-standard configuration, then instead of using the provided AddBlazoredLocalStorage
helper for adding services, you can just add them manually with the configuration you choose.
Services.AddSingleton<ILocalStorageService, LocalStorageService>()
Services.AddSingleton<ISyncLocalStorageService, LocalStorageService>();
from localstorage.
chrissainty I'm having the same problem. So I'm not sure what I should change to make this work properly. You share some code above but you imply this code was for working around and doing some custom implementation.
Do do we inject local storage so we can use it anywhere in our application, correctly?
from localstorage.
Hi @robertdunaway, what exactly is your issue?
from localstorage.
I think this might have done the trick for me. I use the BlazoredLocalService as part of my AppStateServce. I made the change below and my AppStateService class was able to continue receiving the injected local state class.
// builder.Services.AddSingleton<AppStateService>();
builder.Services.AddScoped<AppStateService>();
from localstorage.
Yes, that's because we register our service as scoped. Scoped services can't be injected into singletons.
from localstorage.
After upgrading to .net 6 preview(blazor wasm) i started getting compiler error.
builder.Services.AddSingleton<ILocalStorageService, LocalStorageService>();
builder.Services.AddSingleton<ISyncLocalStorageService, LocalStorageService>();
and if i use the following line i get runtime error
builder.Services.AddBlazoredLocalStorage();
blazor.webassembly.js:1 System.AggregateException: One or more errors occurred. (Cannot consume scoped service 'Blazored.LocalStorage.ILocalStorageService' from singleton 'BlazorBaseApp.Client.Services.CustomAuthenticationStateProvider'.)
---> System.InvalidOperationException: Cannot consume scoped service 'Blazored.LocalStorage.ILocalStorageService' from singleton 'BlazorBaseApp.Client.Services.CustomAuthenticationStateProvider'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.VisitScopeCache(ServiceCallSite scopedCallSite, CallSiteValidatorState state) in Microsoft.Extensions.DependencyInjection.dll:token 0x6000096+0x13
from localstorage.
Related Issues (20)
- How to send facebook token(passport-facebook) from Frontend after I logged in?
- how inject in Code behind in program.cs HOT 5
- AddBlazoredLocalStorage() add public setter for options.JsonSerializerOptions HOT 2
- [Bug] LocalStorage crashes without throwing exception HOT 14
- [Bug] Impossible to make it work HOT 1
- [Bug] ASP.NET Core AggregateException on startup after injecting BlazorLocalStorage with dependency injection HOT 2
- [Bug] Performance Impact on Multiple SetItem Calls
- [Security] Consider updating Microsoft.AspNetCore.Components.Web dependency
- Net 8.0 iOS System.Text.Json.Serialization.JsonConverter System.ArgumentOutOfRangeException [Bug] HOT 1
- Unhandled exception rendering component: Please use dedicated worker for working with JavaScript interop. See https://aka.ms/dotnet-JS-interop-threads
- .Net 8 RenderMode.InteractiveServer CustomAuthenticationStateProvider[Bug] HOT 2
- Error in .NET 8 : Method not found HOT 3
- [Feature Request] Common Interface between ILocalStorageService and ISessionStorageService
- is it not working on net maui Hybrid? HOT 1
- [Bug] Lists of tuples are not being serialized correctly
- blazored.localstorage is missing NuGet package README file
- [Bug] Can't use local storage in a SSR HOT 1
- [Question] How can I use it in program.cs ? HOT 3
- Whether cookie operations can be added
- [Feature Request] An option to automatically add `location.pathname` to keys
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from localstorage.