Latest commit (PR 22): Under Netstandard 3.0: Cannot consume scoped service 'Microsoft.JSInterop.IJSRuntime' from singleton 'Blazor.Extensions.Storage.SessionStorage'
See original GitHub issueUsing .net core 3 preview 4 and your latest commit of PR22, injecting LocalStorage into my class using DI results in error:
Cannot consume scoped service ‘Microsoft.JSInterop.IJSRuntime’ from singleton ‘Blazor.Extensions.Storage.LocalStorage’
I believe this is because your StorageExtensions.cs calls:
AddSingleton<LocalStorage>()
But when your LocalStorage.cs constructor injects IJSRuntime public LocalStorage(IJSRuntime Runtime)
I am guessing that IJSRuntime is added to the Service Collection as Scoped, therefore consuming it from your Singleton StorageExtensions.cs cases this error.
FYI I have tried amending your StorageExtensions.cs to read: AddScoped<LocalStorage>()
. This does compile and run but then any call to await _localStorage.SetItem<>()
never returns…
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (3 by maintainers)
Top GitHub Comments
After a couple of hours I can execute it in server mode. How:
install nuget package configure dependencies by hand using Transient scope:
services.AddTransient<LocalStorage>();
Clone this repo Compile with typescript the ts files in Storage\src\Blazor.Extensions.Storage.JS\src create a javascript file join both created files. I removed the ‘required’ to put all code togheter:
I named this file InitializeStorage.js (very original I know)
Reference this file in _Host.cshtml at the end of the body part:
`<body id="page-top"> <app>@(await Html.RenderComponentAsync<App>())</app> <script src="_framework/blazor.server.js"></script> <script src="~/assets/js/InitializeStorage.js"></script>
</body>`And it started to work. I figured it out the problem to “embed” javascript code from external dll. But this trick works for me. No idea how to contribute and fix this issue once for all.
Thanks @BlackFenix2 for the tips in his fork
The package was published https://www.nuget.org/packages/Blazor.Extensions.Storage/0.2.1
Nuget is indexing and it should be available soon.