Example #1
0
        /// <summary>
        /// Extension method to use the JsonRpc router in the Asp.Net pipeline
        /// </summary>
        /// <param name="app"><see cref="IApplicationBuilder"/> that is supplied by Asp.Net</param>
        /// <param name="configureRouter">Action to configure the router properties</param>
        /// <returns><see cref="IApplicationBuilder"/> that includes the Basic auth middleware</returns>
        public static IApplicationBuilder UseJsonRpc(this IApplicationBuilder app, Action <RpcRouterConfiguration> configureRouter)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (configureRouter == null)
            {
                throw new ArgumentNullException(nameof(configureRouter));
            }

            RpcRouterConfiguration configuration = new RpcRouterConfiguration();

            configureRouter.Invoke(configuration);
            if (configuration.Routes.Count < 1)
            {
                throw new RpcConfigurationException("At least on class/route must be configured for router to work.");
            }

            IRpcInvoker    rpcInvoker    = app.ApplicationServices.GetRequiredService <IRpcInvoker>();
            IRpcParser     rpcParser     = app.ApplicationServices.GetRequiredService <IRpcParser>();
            IRpcCompressor rpcCompressor = app.ApplicationServices.GetRequiredService <IRpcCompressor>();
            ILoggerFactory loggerFactory = app.ApplicationServices.GetService <ILoggerFactory>();
            ILogger        logger        = loggerFactory?.CreateLogger <RpcRouter>();

            app.UseRouter(new RpcRouter(configuration, rpcInvoker, rpcParser, rpcCompressor, logger));
            return(app);
        }
Example #2
0
		/// <param name="serverConfig">Configuration data for the server</param>
		/// <param name="invoker">Component that invokes Rpc requests target methods and returns a response</param>
		/// <param name="parser">Component that parses Http requests into Rpc requests</param>
		/// <param name="compressor">Component that compresses Rpc responses</param>
		/// <param name="logger">Component that logs actions from the router</param>
		/// <param name="routeProvider">Provider that allows the retrieval of all configured routes</param>
		public RpcRouter(IOptions<RpcServerConfiguration> serverConfig, IRpcInvoker invoker, IRpcParser parser, IRpcCompressor compressor, ILogger<RpcRouter> logger,
			IRpcRouteProvider routeProvider)
		{
			if (serverConfig == null)
			{
				throw new ArgumentNullException(nameof(serverConfig));
			}
			if (invoker == null)
			{
				throw new ArgumentNullException(nameof(invoker));
			}
			if (parser == null)
			{
				throw new ArgumentNullException(nameof(parser));
			}
			if (compressor == null)
			{
				throw new ArgumentNullException(nameof(compressor));
			}
			if (routeProvider == null)
			{
				throw new ArgumentNullException(nameof(routeProvider));
			}
			this.serverConfig = serverConfig;
			this.invoker = invoker;
			this.parser = parser;
			this.compressor = compressor;
			this.logger = logger;
			this.routeProvider = routeProvider;
		}
Example #3
0
 /// <param name="serverConfig">Configuration data for the server</param>
 /// <param name="invoker">Component that invokes Rpc requests target methods and returns a response</param>
 /// <param name="parser">Component that parses Http requests into Rpc requests</param>
 /// <param name="logger">Component that logs actions from the router</param>
 public RpcRequestHandler(IOptions <RpcServerConfiguration> serverConfig,
                          IRpcInvoker invoker,
                          IRpcParser parser,
                          ILogger <RpcRequestHandler> logger)
 {
     this.serverConfig = serverConfig ?? throw new ArgumentNullException(nameof(serverConfig));
     this.invoker      = invoker ?? throw new ArgumentNullException(nameof(invoker));
     this.parser       = parser ?? throw new ArgumentNullException(nameof(parser));
     this.logger       = logger;
 }
Example #4
0
 /// <param name="configuration">Configuration data for the router</param>
 /// <param name="invoker">Component that invokes Rpc requests target methods and returns a response</param>
 /// <param name="parser">Component that parses Http requests into Rpc requests</param>
 /// <param name="compressor">Component that compresses Rpc responses</param>
 /// <param name="logger">Component that logs actions from the router</param>
 public RpcRouter(RpcRouterConfiguration configuration, IRpcInvoker invoker, IRpcParser parser, IRpcCompressor compressor, ILogger logger)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (invoker == null)
     {
         throw new ArgumentNullException(nameof(invoker));
     }
     if (parser == null)
     {
         throw new ArgumentNullException(nameof(parser));
     }
     if (compressor == null)
     {
         throw new ArgumentNullException(nameof(compressor));
     }
     this.configuration = configuration;
     this.invoker       = invoker;
     this.parser        = parser;
     this.compressor    = compressor;
     this.logger        = logger;
 }
Example #5
0
 /// <param name="serverConfig">Configuration data for the server</param>
 /// <param name="invoker">Component that invokes Rpc requests target methods and returns a response</param>
 /// <param name="parser">Component that parses Http requests into Rpc requests</param>
 /// <param name="compressor">Component that compresses Rpc responses</param>
 /// <param name="logger">Component that logs actions from the router</param>
 /// <param name="routeProvider">Provider that allows the retrieval of all configured routes</param>
 public RpcRouter(IOptions <RpcServerConfiguration> serverConfig, IRpcInvoker invoker, IRpcParser parser, IRpcCompressor compressor, ILogger <RpcRouter> logger,
                  IRpcRouteProvider routeProvider)
 {
     if (serverConfig == null)
     {
         throw new ArgumentNullException(nameof(serverConfig));
     }
     if (invoker == null)
     {
         throw new ArgumentNullException(nameof(invoker));
     }
     if (parser == null)
     {
         throw new ArgumentNullException(nameof(parser));
     }
     if (compressor == null)
     {
         throw new ArgumentNullException(nameof(compressor));
     }
     if (routeProvider == null)
     {
         throw new ArgumentNullException(nameof(routeProvider));
     }
     this.serverConfig  = serverConfig;
     this.invoker       = invoker;
     this.parser        = parser;
     this.compressor    = compressor;
     this.logger        = logger;
     this.routeProvider = routeProvider;
 }