【发布时间】:2021-12-23 05:56:26
【问题描述】:
这是引发的异常:
我认为这与无法解析我的基类有关。
public class Project : BaseEntity<ProjectId>
{
public string Name { get; private set; }
public string Description { get; private set; }
private List<Asset> _assets = new();
public IReadOnlyList<Asset> Assets => _assets;
public Project(ProjectId id, string name, string description)
{
Id = id;
Name = name;
Description = description;
Validate();
}
...
}
这是我的基地:
public abstract class BaseEntity<TId>
{
public TId Id { get; set; }
public ValidationResult ValidationResult { get; set; }
public bool IsValid => ValidationResult?.IsValid ?? Validate();
protected abstract bool Validate();
protected bool RunValidation<TValidator, TEntity>(TEntity entity, TValidator validator)
where TValidator : AbstractValidator<TEntity>
where TEntity : BaseEntity<TId>
{
ValidationResult = validator.Validate(entity);
return IsValid;
}
这就是我注册服务的方式。
builder.Services
.AddGraphQLServer()
.AddQueryType<ProjectQueries>()
.AddType<ProjectType>();
以及对象类型
public class ProjectType : ObjectType<Project>, IViewModel
{
protected override void Configure(IObjectTypeDescriptor<Project> descriptor)
{
descriptor
.Field(p => p.Id)
.Description("Unique ID for the project.");
descriptor
.Field(p => p.Name)
.Description("Represents the name for the project.");
}
我有什么遗漏吗?
【问题讨论】:
-
何时引发此异常?
-
启动期间。
-
发布完整的异常文本(即 Exception.ToString() 的结果),而不是异常框的图像
标签: c# graphql hotchocolate .net-6.0