我有注册类型时,没有类型错误的注册服务

时间:2020-10-02 15:45:02

标签: blazor blazor-server-side blazor-webassembly

我遵循了在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

将其注入到我的Survey.razor页面中

我遇到了错误:

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'.

0 个答案:

没有答案