- Implemented tests for RouterConfig, RoutingOptions, StaticInstanceConfig, and RouterConfigOptions to ensure default values are set correctly. - Added tests for RouterConfigProvider to validate configurations and ensure defaults are returned when no file is specified. - Created tests for ConfigValidationResult to check success and error scenarios. - Developed tests for ServiceCollectionExtensions to verify service registration for RouterConfig. - Introduced UdpTransportTests to validate serialization, connection, request-response, and error handling in UDP transport. - Added scripts for signing authority gaps and hashing DevPortal SDK snippets.
90 lines
3.5 KiB
C#
90 lines
3.5 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using StellaOps.Router.Common.Abstractions;
|
|
|
|
namespace StellaOps.Router.Transport.InMemory;
|
|
|
|
/// <summary>
|
|
/// Extension methods for registering InMemory transport services.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds the InMemory transport for testing and development.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configure">Optional configuration action.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddInMemoryTransport(
|
|
this IServiceCollection services,
|
|
Action<InMemoryTransportOptions>? configure = null)
|
|
{
|
|
services.AddOptions<InMemoryTransportOptions>();
|
|
if (configure is not null)
|
|
{
|
|
services.Configure(configure);
|
|
}
|
|
|
|
// Singleton registry shared between server and client
|
|
services.TryAddSingleton<InMemoryConnectionRegistry>();
|
|
|
|
// Transport implementations
|
|
services.TryAddSingleton<InMemoryTransportServer>();
|
|
services.TryAddSingleton<InMemoryTransportClient>();
|
|
|
|
// Register interfaces
|
|
services.TryAddSingleton<ITransportServer>(sp => sp.GetRequiredService<InMemoryTransportServer>());
|
|
services.TryAddSingleton<ITransportClient>(sp => sp.GetRequiredService<InMemoryTransportClient>());
|
|
services.TryAddSingleton<IMicroserviceTransport>(sp => sp.GetRequiredService<InMemoryTransportClient>());
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds the InMemory transport server only (for Gateway).
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configure">Optional configuration action.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddInMemoryTransportServer(
|
|
this IServiceCollection services,
|
|
Action<InMemoryTransportOptions>? configure = null)
|
|
{
|
|
services.AddOptions<InMemoryTransportOptions>();
|
|
if (configure is not null)
|
|
{
|
|
services.Configure(configure);
|
|
}
|
|
|
|
services.TryAddSingleton<InMemoryConnectionRegistry>();
|
|
services.TryAddSingleton<InMemoryTransportServer>();
|
|
services.TryAddSingleton<ITransportServer>(sp => sp.GetRequiredService<InMemoryTransportServer>());
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds the InMemory transport client only (for Microservice SDK).
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configure">Optional configuration action.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddInMemoryTransportClient(
|
|
this IServiceCollection services,
|
|
Action<InMemoryTransportOptions>? configure = null)
|
|
{
|
|
services.AddOptions<InMemoryTransportOptions>();
|
|
if (configure is not null)
|
|
{
|
|
services.Configure(configure);
|
|
}
|
|
|
|
services.TryAddSingleton<InMemoryConnectionRegistry>();
|
|
services.TryAddSingleton<InMemoryTransportClient>();
|
|
services.TryAddSingleton<ITransportClient>(sp => sp.GetRequiredService<InMemoryTransportClient>());
|
|
services.TryAddSingleton<IMicroserviceTransport>(sp => sp.GetRequiredService<InMemoryTransportClient>());
|
|
|
|
return services;
|
|
}
|
|
}
|