Skip to content

Issue in chapter 07 Adding data access to Web Assembly #9

Open
@chopper2001

Description

@chopper2001

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:

  1. Spurious line with CustomCssClassProvider instead of closing }
  2. Missing using System.ComponentModel.DataAnnotations;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions