我正在创建一个.tt
将文本转换为模型类的文件,以进行练习。
.cs
生成一个文件,其中包含 all models
,但我希望每个文件都model
保存在.cs
不同文件夹中自己的文件中。
实现这一目标的最佳方法是什么?
我正在尝试在 ASP.NET Core 中使用 Hot Chocolate 设置 GraphApi。
现在我想将我的应用程序拆分为多个项目/组件。有一个 Users 组件,其中的 UsersMutation 包含 1 个字段:
public sealed class UsersMutation
{
public Task CreateUser([Service] ICreateUserMutationHandler handler, CreateUserParameters parameters)
=> handler.Handle(parameters);
}
Run Code Online (Sandbox Code Playgroud)
我尝试将其添加到 GraphQl 架构中,如下所示:
public sealed class Mutation
{
public UsersMutation Users => new UsersMutation();
}
Run Code Online (Sandbox Code Playgroud)
配置:
public static class GraphApiConfiguration
{
public static IServiceCollection AddGraphApi<TQuery, TMutation>(this IServiceCollection services)
where TQuery : class
where TMutation : class
{
services.AddGraphQLServer()
.AddQueryType<TQuery>()
.AddMutationType<TMutation>();
services.AddScoped<TQuery>();
services.AddScoped<TMutation>();
return services;
}
}
Run Code Online (Sandbox Code Playgroud)
最后在startup.cs中:
services.AddGraphApi<Query, Mutation>();
Run Code Online (Sandbox Code Playgroud)
但我在尝试查看游乐场中的架构时遇到以下错误: …