/// <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="builder">Action to configure the endpoints</param> /// <returns><see cref="IApplicationBuilder"/> that includes the Basic auth middleware</returns> public static IApplicationBuilder UseJsonRpc(this IApplicationBuilder app, Action <RpcEndpointBuilder> builder) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var options = new RpcEndpointBuilder(); builder.Invoke(options); StaticRpcMethodData data = options.Resolve(); return(app.UseJsonRpc(data)); }
/// <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="methodProvider">All the available methods to call</param> /// <returns><see cref="IApplicationBuilder"/> that includes the Basic auth middleware</returns> internal static IApplicationBuilder UseJsonRpc(this IApplicationBuilder app, StaticRpcMethodData data) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (data == null) { throw new ArgumentNullException(nameof(data)); } if (app.ApplicationServices.GetService <RpcServicesMarker>() == null) { throw new InvalidOperationException("AddJsonRpc() needs to be called in the ConfigureServices method."); } var router = new RpcHttpRouter(); return(app .Use((context, next) => { context.RequestServices.GetRequiredService <StaticRpcMethodDataAccessor>().Value = data; return next(); }) .UseRouter(router)); }