Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4035

Blazor dependency injection service not registered

$
0
0

I created an ASP.NET Blazor project. There is a Client which is a Blazor WebAssembly application, and it has a BaseLibrary where I store the DTOs and Entities, and a ClientLibrary that I use to call the APIs.

In the ClientLibrary, there is an IGenericServiceInterface interface and a GenericServiceImplementation. The GenericServiceImplementation inherits the functions of the IGenericServiceInterface, specifically for API calls. I have registered all of this in the Client's program.cs file and the _imports.razor.

Program.CS

builder.Services.AddScoped<IGenericServiceInterface<Allergies>, GenericServiceImplementation<Allergies>>();builder.Services.AddScoped<IGenericServiceInterface<Diseases>, GenericServiceImplementation<Diseases>>();builder.Services.AddScoped<IGenericServiceInterface<Ingredient>, GenericServiceImplementation<Ingredient>>();builder.Services.AddScoped<IGenericServiceInterface<Medication>, GenericServiceImplementation<Medication>>();

Imports.razor

`@inject IGenericServiceInterface<Allergies> allergyService @inject IGenericServiceInterface<Diseases> diseaseService@inject IGenericServiceInterface<Ingredient> ingredientService@inject IGenericServiceInterface<Medication> medicationService`

When i run the app and click on the allergies page this issue is display

`Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]      Unhandled exception rendering component: Cannot provide a value for property 'medicationService' on type 'Client.Pages.ContentPages.AdminFunctions.Allergies'. There is no registered service of type 'ClientLibrary.Services.Contracts.IGenericServiceInterface`1[Client.Pages.ContentPages.AdminFunctions.Medication]'.System.InvalidOperationException: Cannot provide a value for property 'medicationService' on type 'Client.Pages.ContentPages.AdminFunctions.Allergies'. There is no registered service of type 'ClientLibrary.Services.Contracts.IGenericServiceInterface`1[Client.Pages.ContentPages.AdminFunctions.Medication]'.   at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass9_0.<CreatePropertyInjector>g__Initialize|1(IServiceProvider serviceProvider, IComponent component)   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType, IComponentRenderMode callerSpecifiedRenderMode, Nullable`1 parentComponentId)   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] frames, Int32 frameIndex, Int32 parentComponentId)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()`

As you can see, I have injected everything everywhere, but I don't understand where the problem is.


Viewing all articles
Browse latest Browse all 4035

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>