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

网站建设辶金手指排名十三php做电商网站

网站建设辶金手指排名十三,php做电商网站,展览设计,网页翻译网站Hot Chocolate 是 .NET 平台下的一个开源组件库, 您可以使用它创建 GraphQL 服务, 它消除了构建成熟的 GraphQL 服务的复杂性, Hot Chocolate 可以连接任何服务或数据源#xff0c;并创建一个有凝聚力的服务#xff0c;为您的消费者提供统一的 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 新增一个Querybuilder.Services.AddQueryTypeMyQuery()//一个Query所有Query写在一起 public class MyQuery{[UseOffsetPaging][UseProjection][UseFiltering][UseSorting]public IQueryableSuperhero GetSuperheroes([Service] ApplicationDbContext context) context.Superheroes;[UseOffsetPaging][UseProjection][UseFiltering][UseSorting]public IQueryableMovie GetMovies([Service] ApplicationDbContext context) context.Movies;[UseOffsetPaging][UseProjection][UseFiltering][UseSorting]public IQueryableSuperpower 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)).AddTypeExtensionSuperheroQuery().AddTypeExtensionMovieQuery().AddTypeExtensionSuperpowerQuery()[ExtendObjectType(Query)]public class SuperheroQuery{[UseOffsetPaging][UseProjection]//始终显示的数据字段无论是否查询该字段[UseFiltering][UseSorting][GraphQLDescription(获取超级英雄集合)]public IQueryableSuperhero GetSuperheroes([Service] ApplicationDbContext context) context.Superheroes;} 创建Mutation自定义错误信息 .AddMutationType(m m.Name(Mutation)).AddTypeExtensionSuperheroMutation()[ExtendObjectType(Mutation)]public class SuperheroMutation{public async TaskBoolean 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 TaskBoolean 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.){}} 创建指令 .AddDirectiveTypeToUpperDirectiveType().AddTypetoLowerDirective()/// summary/// 转大写指令/// /summarypublic class ToUpperDirectiveType : DirectiveType{protected override void Configure(IDirectiveTypeDescriptor descriptor){descriptor.Name(toupper);//descriptor.Argument(name).TypeNonNullTypeStringType();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/// 指令中间件/// /summarypublic 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,passwordMichael,defaultDatabase2)).AddSubscriptionType(q q.Name(Subscription)).AddTypeExtensionSuperheroSubscribe()//.AddSubscriptionTypeSuperheroSubscribe()//指定一个订阅类所有订阅写在一起[ExtendObjectType(Subscription)]public class SuperheroSubscribe{[Subscribe][Topic(SuperheroUpdated)]public async TaskSuperheroDto 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 namereceiver/param/// returns/returnspublic async IAsyncEnumerableSuperheroDto SubscribeToSuperheroDto([Service] ITopicEventReceiver receiver, [Service] ISuperheroRepository _repository){yield return new SuperheroDto { Id Guid.NewGuid(), Name $Name-{DateTime.Now.ToString(HHmmss)} };//return ISourceStreamSuperheroDtovar source await receiver.SubscribeAsyncSuperheroDto(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 namesuperherodto/param/// param name_repository/param/// returns/returns[Topic(SuperheroModified)][Subscribe(With nameof(SubscribeToSuperheroDto))]public async TaskSuperheroDto SuperheroModified([EventMessage] SuperheroDto superherodto){return superherodto;}#endregion} 必须先链接WebSocketMutation事件才会推送 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,passwordMichael,defaultDatabase2)).AddSubscriptionType(q q.Name(Subscription)).AddTypeExtensionSuperheroSubscribe()//.AddSubscriptionTypeSuperheroSubscribe()//指定一个订阅类所有订阅写在一起//.AddTypeExtensionsFromFile(./Stitching.graphql)//.ModifyOptions(options //{// /*// * code-first模式-Explicit:显示绑定(手动绑定字段或者使用ObjectTypeT-override Configure手动设置)// * 显示绑定 必须所有数据都要声明包括 TsortinputTinputTOperationFilterInput等。。。// * Annotation-based模式-Implicit:隐式绑定(默认展示所有字段或者使用ObjectTypeT-override Configure手动设置)// * GraphQLIgnoreAttribute 可过滤不需要的字段// */// options.DefaultBindingBehavior BindingBehavior.Explicit;//}).AddTypeSuperheroType().AddTypeMovieType().AddTypeSuperpowerType()//.AddQueryTypeMyQuery()//一个Query所有Query写在一起.AddQueryType(q q.Name(Query)).AddTypeExtensionSuperheroQuery().AddTypeExtensionMovieQuery().AddTypeExtensionSuperpowerQuery().AddMutationType(m m.Name(Mutation)).AddTypeExtensionSuperheroMutation().AddProjections().AddFiltering().AddSorting().SetPagingOptions(new PagingOptions{MaxPageSize 10000,DefaultPageSize 10,IncludeTotalCount true}).AddDirectiveTypeMyDirectiveType().AddDirectiveTypeToUpperDirectiveType().AddTypetoLowerDirective();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.AddDbContextApplicationDbContext(options options.UseSqlServer(SqlServerConnStr));// Register custom services for the superheroesbuilder.Services.AddScopedISuperheroRepository, SuperheroRepository();builder.Services.AddScopedISuperpowerRepository, SuperpowerRepository();builder.Services.AddScopedIMovieRepository, 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.hkea.cn/news/14557435/

相关文章:

  • 电子商务网站的管理网站建设_超速云建站
  • 站长工具seo综合查询访问app制作图片
  • 用什么框架做网站快上海网站建设 报价
  • 网站推广的几种方法惠州html5网站建设
  • 温州网站排名团队代理服务器地址和端口是多少
  • 做pc端网站如何微官网怎么开通使用
  • 佛山外贸网站建设报价就业指导中心网站建设总结
  • 做兼职用什么网站最好建设部网站注册规划师查询
  • 甘肃住房和城乡建设局网站全面的客户管理系统
  • 大连小程序定制上海网站建设seo推广
  • 美术教育机构网站建设方案品牌排行榜
  • 如何做网站接口鲜花网站建设企划书
  • 做网站赚广告费多么网站建设公司营销推广
  • 百度怎么免费做网站深圳做网站(信科网络)
  • 如何进行外贸网站建设wordpress 个人设置
  • 网站flash引导页下载电子商务说白了是干嘛的
  • 广西中国建设银行网站首页如何在电商平台做好企业网站推广
  • 西安市建网站惠州网站建设制作
  • 做网站在线支付系统多少钱?wordpress 1g内存
  • 企业网站cms源码wordpress 支持 标签
  • 网站设计需求说明书电子商务seo是指什么意思
  • 手表网站官网上海网站建设目的
  • 足球网站模板下载惠州seo计费
  • 网站建设技术及服务承诺微信开发网站开发未来前景
  • 南头专业的网站建设公司叶涛网站推广优化
  • 南昌做网站优化wordpress插件没有效果
  • 商田科技网站网络设计目标
  • 做网站的难点杭州谷歌seo公司
  • 免展网站后台注册怎么做网页调查问卷
  • 淘宝网建设网站意义宁波信誉好全网seo优化