我是.Net Core和Identity Server 4的新手,我遵循了几个教程并获得了运行Asp .Net Core Identity的Identity Server .

然后我有一个单独的API项目,限制路线运行良好 .

所以,假设我希望用户能够在此api上发表评论 .

在我的Identity Server项目中,我有一个名为“ApplicationUser”的模型,扩展了“IdentityUser” .

public class ApplicationUser : IdentityUser
{
}

在我的API项目中,我有一个“评论”模型:

public class Comment
{
    public long Id { get; set; };
    public string Text { get; set; };
}

现在我想知道哪个用户发布了评论,所以我向用户添加了一个外键,并在我的Comment模型中添加了一个指向ApplicationUser的指针

public class Comment
{
    public long Id { get; set; };
    public string Text { get; set; };

    public long UserId { get; set; }
    public ApplicationUser User { get; set; }
}

但由于“ApplicationUser”在我的IdentityServer项目中,我需要在指向IdentityServer项目的Api项目中添加Project依赖项 .

然后在我的“ApplicationUser”模型中,我希望与该用户发布的评论具有一对多的关系,如下所示:

public class ApplicationUser : IdentityUser
{
    public virtual ICollection<Comment> Comments { get; set; }
}

但是在这里我遇到了一个问题,因为我的“IdentityServer”项目无法访问API项目中的“Comment”模型,如果我尝试向该项目添加依赖项,那么我会收到“循环依赖”错误 .

所以我想我这样做是错误的 . 如何以最佳方式从我的API项目模型中访问IdentityServer项目中的用户,反之亦然?

谢谢!