当前位置: 首页 > news >正文

校园网站建设的系统分析官网seo怎么做

校园网站建设的系统分析,官网seo怎么做,幼儿园主题网络图设计ppt,asp框架商城网站模板Hot Chocolate 是 .NET 平台下的一个开源组件库, 您可以使用它创建 GraphQL 服务, 它消除了构建成熟的 GraphQL 服务的复杂性, Hot Chocolate 可以连接任何服务或数据源,并创建一个有凝聚力的服务,为您的消费者提供统一的 API。 我会在 .NET 应用中使用…

Hot Chocolate 是 .NET 平台下的一个开源组件库, 您可以使用它创建 GraphQL 服务, 它消除了构建成熟的 GraphQL 服务的复杂性, Hot Chocolate 可以连接任何服务或数据源,并创建一个有凝聚力的服务,为您的消费者提供统一的 API。

我会在 .NET 应用中使用 Hot Chocolate 组件来构建 GraphQL 服务, 让我们开始吧!

创建服务

  •  创建一个GraphQL服务

        安装nuget包:        

        HotChocolate.AspNetCore // GraphQL -  HotChocolate实现包
        HotChocolate.Data.EntityFramework //HotChocolate-IQueryable 实现包
        HotChocolate.Subscriptions.Redis //redis订阅
        Microsoft.EntityFrameworkCore.SqlServer //orm ef sqlServer
        Microsoft.EntityFrameworkCore.Tools //ef 工具

        builder.Services.AddGraphQLServer()

使用Hot Chocolate

  • 新增一个Query

        builder.Services.AddQueryType<MyQuery>()//一个Query,所有Query写在一起

public class MyQuery{[UseOffsetPaging][UseProjection][UseFiltering][UseSorting]public IQueryable<Superhero> GetSuperheroes([Service] ApplicationDbContext context) =>context.Superheroes;[UseOffsetPaging][UseProjection][UseFiltering][UseSorting]public IQueryable<Movie> GetMovies([Service] ApplicationDbContext context) =>context.Movies;[UseOffsetPaging][UseProjection][UseFiltering][UseSorting]public IQueryable<Superpower> GetSuperpowers([Service] ApplicationDbContext context) =>context.Superpowers;}
  • 使用特性  搜索、排序、投影

         builder.Services.AddProjections()
         .AddFiltering()
        .AddSorting()
        .SetPagingOptions(new PagingOptions
        {
                    MaxPageSize = 10000,
                    DefaultPageSize = 10,
                    IncludeTotalCount = true
        });

  • 创建多个Query,通过ExtendObjectType("Query")关联
.AddQueryType(q => q.Name("Query")).AddTypeExtension<SuperheroQuery>().AddTypeExtension<MovieQuery>().AddTypeExtension<SuperpowerQuery>()[ExtendObjectType("Query")]public class SuperheroQuery{[UseOffsetPaging][UseProjection]//始终显示的数据字段,无论是否查询该字段[UseFiltering][UseSorting][GraphQLDescription("获取超级英雄集合")]public IQueryable<Superhero> GetSuperheroes([Service] ApplicationDbContext context) =>context.Superheroes;}
  • 创建Mutation&自定义错误信息
.AddMutationType(m => m.Name("Mutation")).AddTypeExtension<SuperheroMutation>()[ExtendObjectType("Mutation")]public class SuperheroMutation{public async Task<Boolean> AddSuperheroAsync(SuperheroDto superhero, [Service] ISuperheroRepository _repository, [Service] ITopicEventSender sender){var (Success, KeyId) = await _repository.AddSuperheroAsync(superhero);await sender.SendAsync("SuperheroModified", superhero);return Success;}[Error(typeof(NameTakenException))]public async Task<Boolean> UpdateSuperheroAsync([ID] Guid Id, string name, [Service] ISuperheroRepository _repository, [Service] ITopicEventSender sender){var Success = await _repository.UpdateSuperheroAsync(Id, name);await sender.SendAsync("SuperheroModified", new SuperheroDto{Id = Id,Name = name,Description = "",Height = 0,Movies = null,Superpowers = null});return Success;}}public class NameTakenException : Exception{public NameTakenException(string username): base($"The name {username} is already taken."){}}
  • 创建指令
.AddDirectiveType<ToUpperDirectiveType>().AddType<toLowerDirective>()/// <summary>/// 转大写指令/// </summary>public class ToUpperDirectiveType : DirectiveType{protected override void Configure(IDirectiveTypeDescriptor descriptor){descriptor.Name("toupper");//descriptor.Argument("name").Type<NonNullType<StringType>>();descriptor.Location(DirectiveLocation.Field);//https://chillicream.com/docs/hotchocolate/v13/execution-engine/field-middleware/#field-middleware-as-a-class//中间件 descriptor.Use((next, directive) =>{return async context =>{await next(context);if (context.Result is string str){context.Result = str.ToUpper();}else{context.ReportError("Bad Request.");context.OperationResult.SetResultState(WellKnownContextData.HttpStatusCode, 500);}};});}}/// <summary>/// 转小写指令/// 属性模式/// </summary>[DirectiveType(DirectiveLocation.Field)][toLowerDirectiveMiddleware]public class toLowerDirective{}/// <summary>/// 指令中间件/// </summary>public class toLowerDirectiveMiddlewareAttribute : DirectiveTypeDescriptorAttribute{protected override async void OnConfigure(IDescriptorContext context, IDirectiveTypeDescriptor descriptor, Type type){descriptor.Use((next, directive) =>{return async context =>{await next(context);if (context.Result is string str){context.Result = str.ToLower();}else{context.ReportError("Bad Request.");context.OperationResult.SetResultState(WellKnownContextData.HttpStatusCode, 500);}};});}}
  •  创建订阅(通过webSocket方式)
.AddInMemorySubscriptions()//.AddRedisSubscriptions((sp) => ConnectionMultiplexer.Connect("127.0.0.1:6379,password=Michael,defaultDatabase=2")).AddSubscriptionType(q => q.Name("Subscription")).AddTypeExtension<SuperheroSubscribe>()//.AddSubscriptionType<SuperheroSubscribe>()//指定一个订阅类,所有订阅写在一起[ExtendObjectType("Subscription")]public class SuperheroSubscribe{[Subscribe][Topic("SuperheroUpdated")]public async Task<SuperheroDto> SuperheroUpdated([EventMessage] SuperheroDto superherodto, [Service] ISuperheroRepository _repository){var ret = await _repository.UpdateSuperheroAsync(superherodto.Id, $"{superherodto.Name}_{DateTime.Now.ToString("yyMMdd")}");superherodto.Description = "Subscribe-SuperheroModified";return superherodto;}#region 混合模式(订阅逻辑和解析器分离)/// <summary>/// 数据逻辑处理/// </summary>/// <param name="receiver"></param>/// <returns></returns>public async IAsyncEnumerable<SuperheroDto> SubscribeToSuperheroDto([Service] ITopicEventReceiver receiver, [Service] ISuperheroRepository _repository){yield return new SuperheroDto { Id = Guid.NewGuid(), Name = $"Name-{DateTime.Now.ToString("HHmmss")}" };//return ISourceStream<SuperheroDto>var source = await receiver.SubscribeAsync<SuperheroDto>("SuperheroModified");Task.Delay(3000);await foreach (SuperheroDto superherodto in source.ReadEventsAsync()){superherodto.Name = $"{superherodto.Name}_{DateTime.Now.ToString("HHmmss")}";var ret = await _repository.UpdateSuperheroAsync(superherodto.Id, superherodto.Name);yield return superherodto;}}/// <summary>/// 订阅/// 服务端必须开启websocket/// 订阅人监听websocket/// </summary>/// <param name="superherodto"></param>/// <param name="_repository"></param>/// <returns></returns>[Topic("SuperheroModified")][Subscribe(With = nameof(SubscribeToSuperheroDto))]public async Task<SuperheroDto> SuperheroModified([EventMessage] SuperheroDto superherodto){return superherodto;}#endregion}

必须先链接WebSocket,Mutation事件才会推送 ,GraphQL语法

subscription{superheroUpdated {idnamedescription}
}

 Promgram 整体配置

 var builder = WebApplication.CreateBuilder(args);Microsoft.Extensions.Configuration.ConfigurationManager configuration = builder.Configuration;// Add services to the container.builder.Services.AddControllers();// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbucklebuilder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen();builder.Services.AddGraphQLServer().AddInMemorySubscriptions()//.AddRedisSubscriptions((sp) => ConnectionMultiplexer.Connect("127.0.0.1:6379,password=Michael,defaultDatabase=2")).AddSubscriptionType(q => q.Name("Subscription")).AddTypeExtension<SuperheroSubscribe>()//.AddSubscriptionType<SuperheroSubscribe>()//指定一个订阅类,所有订阅写在一起//.AddTypeExtensionsFromFile("./Stitching.graphql")//.ModifyOptions(options =>//{//    /*//     * code-first模式-Explicit:显示绑定(手动绑定字段,或者使用ObjectType<T>-override Configure手动设置)//     * 显示绑定 必须所有数据都要声明包括 Tsortinput,Tinput,TOperationFilterInput等。。。//     * Annotation-based模式-Implicit:隐式绑定(默认展示所有字段,或者使用ObjectType<T>-override Configure手动设置)//     * GraphQLIgnoreAttribute 可过滤不需要的字段//     *///    options.DefaultBindingBehavior = BindingBehavior.Explicit;//}).AddType<SuperheroType>().AddType<MovieType>().AddType<SuperpowerType>()//.AddQueryType<MyQuery>()//一个Query,所有Query写在一起.AddQueryType(q => q.Name("Query")).AddTypeExtension<SuperheroQuery>().AddTypeExtension<MovieQuery>().AddTypeExtension<SuperpowerQuery>().AddMutationType(m => m.Name("Mutation")).AddTypeExtension<SuperheroMutation>().AddProjections().AddFiltering().AddSorting().SetPagingOptions(new PagingOptions{MaxPageSize = 10000,DefaultPageSize = 10,IncludeTotalCount = true}).AddDirectiveType<MyDirectiveType>().AddDirectiveType<ToUpperDirectiveType>().AddType<toLowerDirective>();string appRoot = builder.Environment.ContentRootPath;Environment.SetEnvironmentVariable("AppDataDirectory", System.IO.Path.Combine(appRoot, "App_Data"));var SqlServerConnStr = Environment.ExpandEnvironmentVariables(configuration.GetConnectionString("SqlServer"));// Add Application Db Context optionsbuilder.Services.AddDbContext<ApplicationDbContext>(options =>options.UseSqlServer(SqlServerConnStr));// Register custom services for the superheroesbuilder.Services.AddScoped<ISuperheroRepository, SuperheroRepository>();builder.Services.AddScoped<ISuperpowerRepository, SuperpowerRepository>();builder.Services.AddScoped<IMovieRepository, MovieRepository>();var app = builder.Build();// Configure the HTTP request pipeline.if (app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}app.UseHttpsRedirection();app.UseAuthorization();app.MapControllers();//使用GraphQL-Subscription 必须开启websocketapp.UseWebSockets();//https://blog.christian-schou.dk/how-to-implement-graphql-in-asp-net-core/app.MapGraphQL();app.Run();
  •  https://localhost:7199/graphql/

 

通过Strawberry Shake,自动链接GraphQL服务,创建客户端

 Introduction - Strawberry Shake - ChilliCream GraphQL Platform

 NSwagStudio,通过Swagger.json 文档创建 TypeScript Client、CSharp Client、CSharp Controller

NSwagStudio · RicoSuter/NSwag Wiki · GitHub

http://www.ysxn.cn/news/3679.html

相关文章:

  • 校园二手物品交易网站怎么做百度指数怎么用
  • 网站怎么做性能测试seo关键词排名优化品牌
  • 班级主页网页设计模板河北百度竞价优化
  • 电商网站开发过程新闻网站软文平台
  • 厦门跨境电商前十北京优化seo
  • 广告推广网站建设今日的最新新闻
  • wordpress培训类网站模板seo网址优化靠谱
  • 北京网站制作一般多少钱电商平台有哪些
  • 药品和医疗器械网站icp备案前置审批流程连接友谊
  • 网站平台建设多少钱杭州网站优化培训
  • 设计免费素材网站有哪些十大it教育培训机构排名
  • 微信连接微网站产品推广朋友圈文案
  • 维力安网站建设公司优化网站建设seo
  • 网站建设对电子商务中的作用搜索关键词优化服务
  • 软件商店下载电脑版官网南京seo关键词排名
  • 免费网站制作模板网络推广和信息流优化一样么
  • 武汉做网站找哪家海南乐秀同城群软件下载
  • 给网站做备案谷歌外贸平台
  • 想做个赚钱的网站不知道做那种2023广东最新疫情
  • 网站服务器的作用在哪里打广告效果最好
  • 网站返回顶部怎么做网页设计友情链接怎么做
  • 帝国cms影视网站模板免费com域名申请注册
  • 做网站的好框架2024免费网站推广大全
  • 网站前台怎么套用织梦后台品牌广告投放
  • wordpress屏蔽右键菜单并提示宁波seo推广优化
  • 做网站的一定要开80或8080端口品牌广告和效果广告的区别
  • 衡水做网站设计外贸建站优化
  • 成都网站建设优创智汇矿坛器材友情交换
  • 医疗网站建设计划书淘宝seo对什么内容优化
  • 双语教学示范课程建设项目网站口碑营销例子