控制器

时间:2018-01-17 18:53:21

标签: asp.net-mvc .net-core-2.0

在我的ASP.NET Core 2 MVC项目中,我正在尝试添加第二个数据上下文" FacilityClaimContext"到我的控制器。到目前为止,一切都很好。我收到错误消息:

" InvalidOperationException:无法解析类型' FacilityClaimApplication.Models.FacilityClaimContext'的服务尝试激活' FacilityClaimApplication.Controllers.FacilitiesController'。"

FacilitiesController.cs

[Authorize]
[Route("[controller]/[action]")]
public class FacilitiesController : Controller
{
    private readonly CQO1Context _context;
    private readonly FacilityClaimContext _facClaimContext;

    public FacilitiesController(CQO1Context context, FacilityClaimContext cfcontext)
    {
        _context = context;
        _facClaimContext = cfcontext;
    }

...     }

Startup.cs

public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")))
            .AddDbContext<CQO1Context>(options => options.UseSqlServer(Configuration.GetConnectionString("Cqo1Connection")));           

        ... }

FacilityClaimContext.cs

namespace FacilityClaimApplication.Models
{
public partial class FacilityClaimContext : DbContext
{
    public virtual DbSet<AspNetRoleClaims> AspNetRoleClaims { get; set; }
    public virtual DbSet<AspNetRoles> AspNetRoles { get; set; }
    public virtual DbSet<AspNetUserClaims> AspNetUserClaims { get; set; }
    public virtual DbSet<AspNetUserLogins> AspNetUserLogins { get; set; }
    public virtual DbSet<AspNetUserRoles> AspNetUserRoles { get; set; }
    public virtual DbSet<AspNetUsers> AspNetUsers { get; set; }
    public virtual DbSet<AspNetUserTokens> AspNetUserTokens { get; set; }
    public virtual DbSet<ClaimedFacilities> ClaimedFacilities { get; set; }
    public virtual DbSet<ClaimedFacilityListingDetails> ClaimedFacilityListingDetails { get; set; }
    public virtual DbSet<ClaimedFacilityListingImages> ClaimedFacilityListingImages { get; set; }
    public virtual DbSet<ClaimedFacilityOwners> ClaimedFacilityOwners { get; set; }
    public virtual DbSet<ClaimedFacilityUserAssociation> ClaimedFacilityUserAssociation { get; set; }

... }

Appsettings.json

  {  "ConnectionStrings": {
"Cqo1Connection": "Server=xxx;Database=CQO1;User=xxx;Password=xxx;MultipleActiveResultSets=true",
"DefaultConnection": "Server=xxx;Database=FacilityClaim;User=xxx;Password=xxx;MultipleActiveResultSets=true"
 } }

ASP.NET Core 2对我来说是新手,我将不胜感激。

0 个答案:

没有答案