Description
I hit an issue following the code in chapter 7 when adding this code:
builder.Services.AddOptions()
.Configure(options =>
{.
options.DataPath = @"........\Data";
options.BlogPostsFolder = "Blogposts";
options.TagsFolder = "Tags";
options.CategoriesFolder = "Categories";
});
builder.Services.AddScoped<IBlogApi, BlogApiJsonDirectAccess>();
When setting the startup project to be BlazorWebAssembly.Server and running I get the following error (partially shown):
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Cannot provide a value for property '_api' on type 'Components.Pages.Index'. There is no registered service of type 'Data.Models.Interfaces.IBlogApi'.
System.InvalidOperationException: Cannot provide a value for property '_api' on type 'Components.Pages.Index'. There is no registered service of type 'Data.Models.Interfaces.IBlogApi'.
at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass7_0.g__Initialize|1(IServiceProvider serviceProvider, IComponent component)
at Microsoft.AspNetCore.Components.ComponentFactory.PerformPropertyInjection(IServiceProvider serviceProvider, IComponent instance)
.....
I suspected I had made some error in my version of the code but could not spot anything. So, I forked the code from this repository and tried running the solution for chapter 7. I hit a couple of other issues first (see below) but once I corrected those, I got the same error as above with the repository code when running the BlazorWebAssembly.Server project, so I don't believe the issue is with my version.
As an aside, if I add the code to the BlazorWebAssemblyClient project just after the add services for HttpClient the BlazorWebAssembly.Server project does then start without the error above.
I do hit another issue if it starts this way, in that no data is saved to the filesystem, but that may be a consequence of the above issue.
The two issues I had to resolve prior to being able to build the solutions in Chapter 7 were in Data.Models\Models. In both Tags.cs and Categories.cs there are two issues:
- Spurious line with CustomCssClassProvider instead of closing }
- Missing using System.ComponentModel.DataAnnotations;
Activity