Adding the API to Blazor
We now have a way to access JSON files stored on our file system. In the repo on GitHub, you can find more ways of storing our data with RavenDB or SQL Server, but be mindful to keep the focus on what is important (Blazor).
Now it’s time to add the API to our Blazor Server project:
- In the
BlazorWebApp
project, add a project reference to theData
project. OpenProgram.cs
and add the following namespaces:using Data; using Data.Models.Interfaces;
- Add the following code after .AddInteractiveWebAssemblyComponents();:
builder.Services.AddOptions<BlogApiJsonDirectAccessSetting>().Configure(options => { options.DataPath = @"..\..\..\Data\"; options.BlogPostsFolder = "Blogposts"; options.TagsFolder = "Tags"; options.CategoriesFolder = "Categories"; options.CommentsFolder = "Comments"; }); builder.Services.AddScoped<IBlogApi, BlogApiJsonDirectAccess...