示例#1
0
 /// <summary>
 /// Adds all the public JSON-RPC service types in the assembly of specified <see cref="Type"/>
 /// to the built <see cref="IJsonRpcServiceHost"/>.
 /// </summary>
 /// <typeparam name="T">A type. The search will be performed in the assembly where this type is in.</typeparam>
 public static IJsonRpcBuilder RegisterFromAssembly <T>(this IJsonRpcBuilder builder)
 {
     if (builder == null)
     {
         throw new ArgumentNullException(nameof(builder));
     }
     builder.Register(typeof(T).GetTypeInfo().Assembly);
     return(builder);
 }
示例#2
0
 /// <summary>
 /// Adds a JSON-RPC service to the built <see cref="IJsonRpcServiceHost"/>.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 public static IJsonRpcBuilder Register <TService>(this IJsonRpcBuilder builder) where TService : JsonRpcService
 {
     if (builder == null)
     {
         throw new ArgumentNullException(nameof(builder));
     }
     builder.Register(typeof(TService));
     return(builder);
 }
示例#3
0
 /// <summary>
 /// Adds a handler to intercept the JSON RPC requests.
 /// </summary>
 /// <param name="handler">The handler to be added.</param>
 /// <remarks>
 /// If there are multiple calls to this method, the last handler applied will be
 /// the fist to receive the request.
 /// </remarks>
 public static void Intercept(this IJsonRpcBuilder builder, Func <RequestContext, Func <Task>, Task> handler)
 {
     if (builder == null)
     {
         throw new ArgumentNullException(nameof(builder));
     }
     if (handler == null)
     {
         throw new ArgumentNullException(nameof(handler));
     }
     builder.Intercept(next => (context => handler(context, () => next(context))));
 }
示例#4
0
 /// <summary>
 /// Adds all the public JSON-RPC service types in the assembly to the built <see cref="IJsonRpcServiceHost"/>.
 /// </summary>
 /// <param name="assembly">The assembly to search services in.</param>
 /// <exception cref="ArgumentNullException"><paramref name="assembly"/> is <c>null</c>.</exception>
 public static IJsonRpcBuilder Register(this IJsonRpcBuilder builder, Assembly assembly)
 {
     if (builder == null)
     {
         throw new ArgumentNullException(nameof(builder));
     }
     foreach (var t in assembly.ExportedTypes
              .Where(t => typeof(JsonRpcService).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo())))
     {
         builder.Register(t);
     }
     return(builder);
 }