In my .Net CORE 5 (imported support files v5.0.12) Blazor PWA VS-2019 solution, I "had" a working 'Customer'-(data/app)service and Blazor pages to List and CRUD the Customer records (works as expected). I created similar 'Vehicle' files for both the SERVER-project and the CLIENT-project (of course changing the model field-references).
There are NO compilation errors yet, when I try to show the "VehicleList" page, this error appears in the Output-window:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Cannot provide a value for property '_vehicleService' on type 'MyCore5AppPWA.Client.Pages.VehicleList'. There is no registered service of type 'MyCore5AppPWA.Client.Services.IVehicleService'. System.InvalidOperationException: Cannot provide a value for property '_vehicleService' on type 'MyCore5AppPWA.Client.Pages.VehicleList'. There is no registered service of type 'MyCore5AppPWA.Client.Services.IVehicleService'. at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass6_0.g__Initialize|2(IServiceProvider serviceProvider, IComponent component)
Please note the above notation of "...c__DisplayClass6_0..." that is curious to me (not knowing the significance of this). I have read many of the similar questions/answers related to the subject of this post that do not correct the error.
Here is a snippet from the Startup.cs file:
public void ConfigureServices(IServiceCollection services) {
_ = services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbConnection")));
services.AddScoped<ICustomerRepository, CustomerRepository>();
services.AddScoped<IVehicleRepository, VehicleRepository>();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddScoped<WeatherForecastService>();
}
Here is the snippet from the "VehicleList.razor' code file.
//html... declarations.
@layout MainLayout
@page "/vehiclelist"
@using MyCore5AppPWA.Client.Services;
@using MyCore5AppPWA.Shared
//...html omitted...//
@code {
[Inject]
private IVehicleService _vehicleService { get; set; }
[Inject]
private NavigationManager navigationManager { get; set; } ...other code...
I also have in the SERVER-project/Controllers subfolder a "CustomerController.cs" and a "VehicleController.cs".
Since I am rather new to Blazor/Core-5/PWA, I conclude that I am missing something regarding adding new service(s) to the PWA projects.
Your comments and suggestions are very welcome. thanks John