Exemple #1
0
 /// <summary> 使用Session。 </summary>
 /// <param name="builder">服务构建者。</param>
 /// <returns>服务构建者。</returns>
 public static IMicroClientBuilder AddSession <T>(this IMicroClientBuilder builder)
     where T : class, IPrincipalAccessor
 {
     //Session
     builder.AddScoped <IPrincipalAccessor, T>();
     builder.AddScoped <IMicroSession, ClaimMicroSession>();
     return(builder);
 }
Exemple #2
0
 /// <summary> 使用Json编解码器。 </summary>
 /// <param name="builder">服务构建者。</param>
 /// <returns>服务构建者。</returns>
 public static IMicroClientBuilder AddJsonCodec(this IMicroClientBuilder builder)
 {
     builder.AddSingleton <IMessageSerializer, JsonMessageSerializer>();
     builder.AddSingleton <IClientMessageCodec, JsonCodec>(provider =>
     {
         var serializer = provider.GetService <IMessageSerializer>(ServiceCodec.Json);
         var config     = provider.GetService <SpearConfig>();
         return(new JsonCodec(serializer, config));
     });
     return(builder);
 }
Exemple #3
0
 /// <summary> 使用Json编解码器。 </summary>
 /// <param name="builder">服务构建者。</param>
 /// <returns>服务构建者。</returns>
 public static IMicroClientBuilder AddProtoBufCodec(this IMicroClientBuilder builder)
 {
     builder.Services.AddSingleton <IMessageSerializer, ProtoBufferSerializer>();
     builder.Services.AddSingleton <IClientMessageCodec, ProtoBufferCodec>(provider =>
     {
         var serializer = provider.GetService <IMessageSerializer>(ServiceCodec.ProtoBuf);
         var config     = provider.GetService <SpearConfig>();
         return(new ProtoBufferCodec(serializer, config));
     });
     return(builder);
 }
 /// <summary> 使用Consul作为服务注册和发现的组件 </summary>
 /// <param name="builder"></param>
 /// <param name="server"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddConsul(this IMicroClientBuilder builder, string server,
                                             string token = null)
 {
     builder.AddMemoryCache();
     builder.AddSingleton <IServiceFinder>(provider =>
     {
         var cache = provider.GetService <IMemoryCache>();
         return(new ConsulServiceFinder(cache, server, token));
     });
     return(builder);
 }
Exemple #5
0
 /// <summary> 添加默认服务路由 </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="builder"></param>
 /// <param name="routerAction"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddDefaultRouter(this IMicroClientBuilder builder, Action <DefaultServiceRouter> routerAction = null)
 {
     builder.AddSingleton <DefaultServiceRouter>();
     builder.AddSingleton <IServiceFinder>(provider =>
     {
         var router = provider.GetService <DefaultServiceRouter>();
         routerAction?.Invoke(router);
         return(router);
     });
     return(builder);
 }
 /// <summary>
 /// 使用Consul作为服务注册和发现的组件
 /// 读取配置:consul
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="optionAction"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddConsul(this IMicroClientBuilder builder, Action <ConsulOption> optionAction = null)
 {
     builder.AddMemoryCache();
     builder.AddSingleton <IServiceFinder>(provider =>
     {
         var option = ConsulOption.Config();
         optionAction?.Invoke(option);
         var cache = provider.GetService <IMemoryCache>();
         return(new ConsulServiceFinder(cache, option.Server, option.Token));
     });
     return(builder);
 }
 /// <summary> 使用Nacos服务发现 </summary>
 /// <param name="builder"></param>
 /// <param name="configAction"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddNacos(this IMicroClientBuilder builder,
                                            Action <NacosConfig> configAction = null)
 {
     builder.Services.AddMemoryCache();
     builder.Services.AddNacosCore(configAction);
     builder.Services.AddSingleton <IServiceFinder>(provider =>
     {
         var config = provider.GetService <NacosConfig>();
         var client = provider.GetService <INacosClient>();
         var cache  = provider.GetService <IMemoryCache>();
         var logger = provider.GetService <ILogger <NacosServiceFinder> >();
         return(new NacosServiceFinder(config, client, logger, cache));
     });
     return(builder);
 }
Exemple #8
0
 /// <summary> 使用Session。 </summary>
 /// <param name="builder">服务构建者。</param>
 /// <returns>服务构建者。</returns>
 public static IMicroClientBuilder AddSession(this IMicroClientBuilder builder)
 {
     //Session
     builder.AddSession <DefaultPrincipalAccessor>();
     return(builder);
 }
 /// <summary> 使用DotNetty的GRpc传输协议 </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddGrpcProtocol(this IMicroClientBuilder builder)
 {
     builder.Services.AddSingleton <IProxyFactory, GrpcProxyFactory>();
     builder.Services.AddSingleton <IMicroClientFactory, GrpcClientFactory>();
     return(builder);
 }
 /// <summary> 使用Http传输协议 </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddHttpProtocol(this IMicroClientBuilder builder)
 {
     builder.AddHttpClient();
     builder.AddSingleton <IMicroClientFactory, HttpClientFactory>();
     return(builder);
 }
Exemple #11
0
 /// <summary> 添加微服务客户端 </summary>
 /// <param name="services"></param>
 /// <param name="builderAction"></param>
 /// <returns></returns>
 public static IServiceCollection AddMicroClient(this IMicroClientBuilder services, Action <IMicroClientBuilder> builderAction)
 {
     builderAction.Invoke(services);
     services.AddProxy <ClientProxy>();
     return(services);
 }
Exemple #12
0
 /// <summary> 使用DotNetty的TCP传输协议 </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddWebSocketProtocol(this IMicroClientBuilder builder)
 {
     builder.Services.AddSingleton <IMicroClientFactory, WebSocketClientFactory>();
     return(builder);
 }
Exemple #13
0
 /// <summary> 使用DotNetty的TCP传输协议 </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IMicroClientBuilder AddTcpProtocol(this IMicroClientBuilder builder)
 {
     builder.AddSingleton <IMicroClientFactory, DotNettyClientFactory>();
     return(builder);
 }