Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions HealthMonitoring.Client/HealthMonitoringRegistrationClient.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System.Net.Http.Json;
using System.Text.Json;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace HealthMonitoring.Client;
Comment thread
StuartFerguson marked this conversation as resolved.
Resolved

public sealed class HealthMonitoringRegistrationClientOptions
{
public Uri MonitoringServerUrl { get; set; } = new("http://localhost:9620");
}

public sealed class ServiceRegistrationOptions
{
public string ServiceId { get; init; } = string.Empty;
Expand Down Expand Up @@ -165,20 +159,3 @@ private sealed record ServiceIdentityPayload(Guid Id, string ServiceId, string N
private sealed record DependencyMappingPayload(string DependencyName, Guid TargetMonitoredServiceId);
private sealed record DependencyLinkResponsePayload(Guid Id, string DependencyName, Guid TargetMonitoredServiceId, string TargetServiceId, string TargetServiceName);
}

public static class HealthMonitoringRegistrationClientServiceCollectionExtensions
{
public static IHttpClientBuilder AddHealthMonitoringRegistrationClient(this IServiceCollection services, Action<HealthMonitoringRegistrationClientOptions> configure)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configure);
var options = new HealthMonitoringRegistrationClientOptions();
configure(options);
if (!options.MonitoringServerUrl.IsAbsoluteUri) throw new ArgumentException("The monitoring server URL must be absolute.", nameof(configure));

return services.AddHttpClient<IHealthMonitoringRegistrationClient, HealthMonitoringRegistrationClient>(client =>
{
client.BaseAddress = options.MonitoringServerUrl;
});
}
}
20 changes: 2 additions & 18 deletions HealthMonitoring.Client/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HealthMonitoring.Client

Reusable .NET client for service self-registration and dependency mapping.
Reusable .NET client for configuration-based service self-registration and dependency mapping.

For automatic registration at application startup, add this configuration:

Expand Down Expand Up @@ -32,20 +32,4 @@ services.AddHealthMonitoringRegistration(configuration);
The client registers the service and dependency mappings once during application startup. Registration is idempotent.
If the `HealthMonitoring` section is absent, no registration is attempted and the application starts normally.

```csharp
services.AddHealthMonitoringRegistrationClient(options =>
{
options.MonitoringServerUrl = new Uri("http://localhost:9620");
});

var result = await client.RegisterAndConfigureAsync(
new ServiceRegistrationOptions
{
ServiceId = "payments-api",
Name = "Payments API",
HealthUrl = new Uri("https://payments-api/health")
},
[new DependencyMappingOptions("Security Service", "security-service")]);
```

Registration is idempotent. Dependency mappings are resolved by `TargetServiceId` and are created or updated as needed.
Dependency mappings are resolved by `TargetServiceId` and are created or updated as needed.
Loading