- Added InMemoryTransportOptions class for configuration settings including timeouts and latency. - Developed InMemoryTransportServer class to handle connections, frame processing, and event management. - Created ServiceCollectionExtensions for easy registration of InMemory transport services. - Established project structure and dependencies for InMemory transport library. - Implemented comprehensive unit tests for endpoint discovery, connection management, request/response flow, and streaming capabilities. - Ensured proper handling of cancellation, heartbeat, and hello frames within the transport layer.
76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
namespace StellaOps.Microservice;
|
|
|
|
/// <summary>
|
|
/// Default implementation of endpoint registry using path matchers.
|
|
/// </summary>
|
|
public sealed class EndpointRegistry : IEndpointRegistry
|
|
{
|
|
private readonly List<RegisteredEndpoint> _endpoints = [];
|
|
private readonly bool _caseInsensitive;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="EndpointRegistry"/> class.
|
|
/// </summary>
|
|
/// <param name="caseInsensitive">Whether path matching should be case-insensitive.</param>
|
|
public EndpointRegistry(bool caseInsensitive = true)
|
|
{
|
|
_caseInsensitive = caseInsensitive;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registers an endpoint descriptor.
|
|
/// </summary>
|
|
/// <param name="endpoint">The endpoint descriptor to register.</param>
|
|
public void Register(EndpointDescriptor endpoint)
|
|
{
|
|
var matcher = new PathMatcher(endpoint.Path, _caseInsensitive);
|
|
_endpoints.Add(new RegisteredEndpoint(endpoint, matcher));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registers multiple endpoint descriptors.
|
|
/// </summary>
|
|
/// <param name="endpoints">The endpoint descriptors to register.</param>
|
|
public void RegisterAll(IEnumerable<EndpointDescriptor> endpoints)
|
|
{
|
|
foreach (var endpoint in endpoints)
|
|
{
|
|
Register(endpoint);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public bool TryMatch(string method, string path, out EndpointMatch? match)
|
|
{
|
|
match = null;
|
|
|
|
foreach (var registered in _endpoints)
|
|
{
|
|
// Check method match (case-insensitive)
|
|
if (!string.Equals(registered.Endpoint.Method, method, StringComparison.OrdinalIgnoreCase))
|
|
continue;
|
|
|
|
// Check path match
|
|
if (registered.Matcher.TryMatch(path, out var parameters))
|
|
{
|
|
match = new EndpointMatch
|
|
{
|
|
Endpoint = registered.Endpoint,
|
|
PathParameters = parameters
|
|
};
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IReadOnlyList<EndpointDescriptor> GetAllEndpoints()
|
|
{
|
|
return _endpoints.Select(e => e.Endpoint).ToList();
|
|
}
|
|
|
|
private sealed record RegisteredEndpoint(EndpointDescriptor Endpoint, PathMatcher Matcher);
|
|
}
|