我遵循了在Blazor应用程序中保存数据的教程。我有一个ApplicationDbContext.cs
文件:
using Microsoft.EntityFrameworkCore;
using BlazorApp1.Shared.Models;
using System;
namespace BlazorApp1.Shared.Data
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<SurveyModel> surveyModel { get; set; }
}
}
并且我已将其注册为startup.cs
中的服务:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
我已使用@inject BlazorApp1.Shared.Data.ApplicationDbContext _context
我遇到了错误:
Unhandled exception rendering component: Cannot provide a value for property '_context' on type 'BlazorApp1.Client.Pages.Survey'. There is no registered service of type 'BlazorApp1.Shared.Data.ApplicationDbContext'.