Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

blazor - 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'.

question from:https://stackoverflow.com/questions/66068554/blasor-wasm-error-there-is-no-registered-service-of-type-myapp-services-myservi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are injecting by interface.

@inject IMyService MyService

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...