Dapper.GraphQL 项目使用教程

Dapper.GraphQL 项目使用教程

Dapper.GraphQLA .NET Core library designed to integrate the Dapper and graphql-dotnet projects with ease-of-use in mind and performance as the primary concern.项目地址:https://gitcode.com/gh_mirrors/da/Dapper.GraphQL

1. 项目的目录结构及介绍

Dapper.GraphQL 项目的目录结构如下:

Dapper.GraphQL/
├── Dapper.GraphQL.sln
├── LICENSE
├── README.md
├── src/
│   ├── Dapper.GraphQL/
│   │   ├── Controllers/
│   │   ├── Models/
│   │   ├── GraphQL/
│   │   ├── Services/
│   │   ├── Dapper.GraphQL.csproj
│   │   ├── appsettings.json
│   │   ├── Program.cs
│   │   ├── Startup.cs
│   ├── Dapper.GraphQL.Test/
│   │   ├── EntityMappers/
│   │   ├── QueryBuilders/
│   │   ├── Dapper.GraphQL.Test.csproj
├── test/
│   ├── Dapper.GraphQL.IntegrationTests/
│   │   ├── Dapper.GraphQL.IntegrationTests.csproj

目录结构介绍

  • Dapper.GraphQL.sln: 解决方案文件,用于在 Visual Studio 或其他 IDE 中打开项目。
  • LICENSE: 项目的许可证文件。
  • README.md: 项目的说明文档。
  • src/: 源代码目录。
    • Dapper.GraphQL/: 主项目目录。
      • Controllers/: 包含 API 控制器。
      • Models/: 包含数据模型。
      • GraphQL/: 包含 GraphQL 相关代码。
      • Services/: 包含业务逻辑服务。
      • Dapper.GraphQL.csproj: 主项目文件。
      • appsettings.json: 配置文件。
      • Program.cs: 程序入口文件。
      • Startup.cs: 启动配置文件。
    • Dapper.GraphQL.Test/: 测试项目目录。
      • EntityMappers/: 包含实体映射代码。
      • QueryBuilders/: 包含查询构建代码。
      • Dapper.GraphQL.Test.csproj: 测试项目文件。
  • test/: 测试代码目录。
    • Dapper.GraphQL.IntegrationTests/: 集成测试项目目录。
      • Dapper.GraphQL.IntegrationTests.csproj: 集成测试项目文件。

2. 项目的启动文件介绍

Program.cs

Program.cs 是项目的入口文件,负责配置和启动应用程序。以下是示例代码:

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Dapper.GraphQL
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}

Startup.cs

Startup.cs 文件负责配置应用程序的服务和请求管道。以下是示例代码:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Dapper.GraphQL
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddGraphQLServices();
            services.AddDapperGraphQL();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

3. 项目的配置文件介绍

appsettings.json

`appsettings

Dapper.GraphQLA .NET Core library designed to integrate the Dapper and graphql-dotnet projects with ease-of-use in mind and performance as the primary concern.项目地址:https://gitcode.com/gh_mirrors/da/Dapper.GraphQL

  • 24
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

葛依励Kenway

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值