/// <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">(Optional) Action to configure the endpoints. Will default to include all controllers that derive from `RpcController`</param> /// <returns><see cref="IApplicationBuilder"/> that includes the Basic auth middleware</returns> public static IApplicationBuilder UseJsonRpc(this IApplicationBuilder app, Action <RpcEndpointBuilder>?builder = null) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var options = new RpcEndpointBuilder(); builder = builder ?? BuildFromBaseController <RpcController>; builder.Invoke(options); RpcRouteMetaData data = options.Resolve(); return(app.UseJsonRpc(data)); }
private static void BuildFromBaseController <T>(RpcEndpointBuilder builder) { Type baseControllerType = typeof(T); IEnumerable <Type> controllers = Assembly .GetEntryAssembly() ! .GetReferencedAssemblies() .Select(Assembly.Load) .SelectMany(x => x.DefinedTypes) .Concat(Assembly.GetEntryAssembly() !.DefinedTypes) .Where(t => !t.IsAbstract && (t == baseControllerType || t.IsSubclassOf(baseControllerType))); foreach (Type type in controllers) { builder.AddController(type); } }
/// <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)); }