Search code examples
blazorblazor-client-side.net-5

Blasor WASM error There is no registered service of type <MyApp.Services.MyService>


I am creating a .Net 5 Blazor WASM non-hosted app. In this configuration there is only one project -- The client. We are told to register our services in Program.cs with this configuration which I have done like this builder.Services.AddScoped<IMyService, MyService>(); In _Imports.razor I also added @using MyApp.Services. In my component I have added @inject Services.MyService MyService and on the page component I have <MyListComponent /> but I still get the following error when browsing to that page:

Unhandled exception rendering component: Cannot provide a value for property 'MyService' on type 'MyApp.Shared.MyList'. There is no registered service of type 'MyApp.Services.MyService'.


Solution

  • You are injecting by interface.

    @inject IMyService MyService