/// <summary>
 /// Uses a <see cref="JsonRpcContractResolver"/> with <see cref="CamelCaseJsonRpcNamingStrategy"/> and
 /// <see cref="CamelCaseJsonValueConverter"/>.
 /// </summary>
 public static JsonRpcOptions UseCamelCaseContractResolver(this JsonRpcOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.ContractResolver = new JsonRpcContractResolver
     {
         NamingStrategy          = new CamelCaseJsonRpcNamingStrategy(),
         ParameterValueConverter = new CamelCaseJsonValueConverter(),
     };
     return(options);
 }
        /// <summary>
        /// Registers <see cref="IJsonRpcServiceHost"/> and <see cref="AspNetCoreRpcServerHandler"/> singletons
        /// in <see cref="IServiceCollection"/>.
        /// </summary>
        /// <param name="serviceCollection">The service collection.</param>
        /// <param name="setupAction">The delegate used to configure the <see cref="JsonRpcServiceHostBuilder"/>.</param>
        /// <returns>A builder used to register JSON RPC services and middlewares.</returns>
        public static IJsonRpcBuilder AddJsonRpc(this IServiceCollection serviceCollection,
                                                 Action <JsonRpcOptions> setupAction)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }
            var options = new JsonRpcOptions();

            setupAction?.Invoke(options);
            var builder = new JsonRpcBuilder(options, serviceCollection);

            serviceCollection.AddSingleton(provider => builder.BuildServiceHost(provider));
            serviceCollection.AddSingleton <AspNetCoreRpcServerHandler>();
            return(builder);
        }
Ejemplo n.º 3
0
 public JsonRpcBuilder(JsonRpcOptions options, IServiceCollection serviceCollection)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     this.serviceCollection = serviceCollection ?? throw new ArgumentNullException(nameof(serviceCollection));
     injectServices         = options.InjectServiceTypes;
     serviceHostBuilder     = new JsonRpcServiceHostBuilder
     {
         ContractResolver = options.ContractResolver,
         LoggerFactory    = options.LoggerFactory,
         ServiceFactory   = options.ServiceFactory,
         MethodBinder     = options.MethodBinder
     };
 }