using EdjCase.JsonRpc.Router.MethodProviders;
using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace EdjCase.JsonRpc.Router.Abstractions
{
///
/// Interface to provide the middleware with available routes and their criteria
///
public interface IRpcRouteProvider
{
RpcPath BaseRequestPath { get; }
List GetMethodsByPath(RpcPath path);
}
#if !NETSTANDARD1_3
public class RpcAutoRoutingOptions
{
///
/// Sets the required base path for the request url to match against
///
public RpcPath BaseRequestPath { get; set; }
public Type BaseControllerType { get; set; } = typeof(RpcController);
}
#endif
public class RpcManualRoutingOptions
{
///
/// Sets the required base path for the request url to match against
///
public RpcPath BaseRequestPath { get; set; }
public Dictionary> Routes { get; set; } = new Dictionary>();
public void RegisterMethods(RpcPath path, IRpcMethodProvider methodProvider)
{
if (!this.Routes.TryGetValue(path, out List methodProviders))
{
methodProviders = new List();
this.Routes[path] = methodProviders;
}
methodProviders.Add(methodProvider);
}
public void RegisterController(RpcPath path = default(RpcPath))
{
this.RegisterMethods(path, new ControllerPublicMethodProvider(typeof(T)));
}
}
public interface IRpcMethodProvider
{
List GetRouteMethods();
}
}