RpcSingleRouteProvider.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using EdjCase.JsonRpc.Router.Abstractions;
  2. using EdjCase.JsonRpc.Router.MethodProviders;
  3. using Microsoft.Extensions.Options;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace EdjCase.JsonRpc.Router.RouteProviders
  10. {
  11. public class RpcSingleRouteProvider : IRpcRouteProvider
  12. {
  13. public IOptions<SingleRouteOptions> Options { get; }
  14. public RpcPath BaseRequestPath { get; }
  15. public RpcSingleRouteProvider(IOptions<SingleRouteOptions> options)
  16. {
  17. this.Options = options ?? throw new ArgumentNullException(nameof(options));
  18. this.BaseRequestPath = this.Options.Value?.BaseRequestPath ?? RpcPath.Default;
  19. }
  20. /// <summary>
  21. /// Gets all the method providers for the specified path
  22. /// </summary>
  23. /// <param name="path">Path to the methods</param>
  24. /// <returns>All method providers for the specified path</returns>
  25. public List<IRpcMethodProvider> GetMethodsByPath(RpcPath path) => this.Options.Value?.MethodProviders ?? new List<IRpcMethodProvider>();
  26. }
  27. public class SingleRouteOptions
  28. {
  29. public List<IRpcMethodProvider> MethodProviders { get; set; } = new List<IRpcMethodProvider>();
  30. public RpcPath BaseRequestPath { get; set; } = RpcPath.Default;
  31. public void AddClass<T>()
  32. {
  33. this.MethodProviders.Add(new ControllerPublicMethodProvider(typeof(T)));
  34. }
  35. }
  36. }