Blazor.IndexedDB.Framework icon indicating copy to clipboard operation
Blazor.IndexedDB.Framework copied to clipboard

Cannot consume scoped service

Open dmarciano opened this issue 4 years ago • 3 comments

I installed the NuGet package and followed the code samples provided, but when I attempted to run the site I get the following error message:

InvalidOperationException: Error while validating the service descriptor 'ServiceType: Blazor.IndexedDB.Framework.IIndexedDbFactory Lifetime: Singleton ImplementationType: Blazor.IndexedDB.Framework.IndexedDbFactory': Cannot consume scoped service 'Microsoft.JSInterop.IJSRuntime' from singleton 'Blazor.IndexedDB.Framework.IIndexedDbFactory'.

In the Startup.cs file, if I add the library as a transient (i.e. services.AddTransient<IIndexedDbFactory, IndexedDbFactory>();) then my site will load but when I try to call the create method I get an error about TimeGhost not being found in the window. I tried searching online for anything about TimeGhost but had no luck.

dmarciano avatar Jul 14 '19 06:07 dmarciano

So after a lot of trial and error I was finally able to get this to work. It required me to do three things:

  1. Add the indexedDb.Blazor.js file to my project and include it in my _Host.cshtml file using a
  2. In the Startup.cs I had to add it to the services as a transient: services.AddTransient<IIndexedDbFactory, IndexedDbFactory>();
  3. In the indexedDb.Blazor.js I had to change the line instanceWrapper.instance.invokeMethod(instanceWrapper.methodName, "Hello from the other side"); to instanceWrapper.instance.invokeMethodAsync(instanceWrapper.methodName, "Hello from the other side");

Once I did those three things the library worked successfully. I was able to add, retrieve, and remove entries from the IndexedDB in Chrome. Not sure why I had to make those three changes, but hopefully it will help someone else.

dmarciano avatar Jul 14 '19 08:07 dmarciano

Hi, would it be possible for you, if the issue persisted, to maybe provide an example project where the issue is reproducible?

Sadly I currently don't have to much time so it may take a while for me to come back at you.

Thank you for your patience :)

Reshiru avatar Jul 24 '19 17:07 Reshiru

So after a lot of trial and error I was finally able to get this to work. It required me to do three things:

  1. Add the indexedDb.Blazor.js file to my project and include it in my _Host.cshtml file using a
  2. In the Startup.cs I had to add it to the services as a transient: services.AddTransient<IIndexedDbFactory, IndexedDbFactory>();
  3. In the indexedDb.Blazor.js I had to change the line instanceWrapper.instance.invokeMethod(instanceWrapper.methodName, "Hello from the other side"); to instanceWrapper.instance.invokeMethodAsync(instanceWrapper.methodName, "Hello from the other side");

Once I did those three things the library worked successfully. I was able to add, retrieve, and remove entries from the IndexedDB in Chrome. Not sure why I had to make those three changes, but hopefully it will help someone else.

Hi dmarciano can you please tell me where can i get indexeddb.blazer.js file

khalilsaqib avatar Aug 26 '20 04:08 khalilsaqib