Adding the API to Blazor
We now have a way to access JSON files stored on our filesystem. In the repo on GitHub there will be more ways of storing our data with RavenDB or SQL server, but to keep the focus on what is important (Blazor) we will not dig deeper into these technologies.
Now it’s time to add the API to our Blazor Server project.
- In the
BlazorServer
project add project reference to the projectData
. - Open
program.cs
and add the following code:
builder.Services.AddOptions<BlogApiJsonDirectAccessSetting>()
.Configure(options =>
{
options.DataPath = @"C:\Code\B16009SecondEdition\Data\";
options.BlogPostsFolder = "Blogposts";
options.TagsFolder = "Tags";
options.CategoriesFolder = "Categories";
});
builder.Services.AddScoped<IBlogApi, BlogApiJsonDirectAccess>();
This is the setting for where we want to store our files, change the data path property to where you want to store...