Fast.Consul
Public members, parameters, returns, and exceptions
Targets: net8.0;net9.0;net10.0.
Contract and constraints
Service registration, health checks and KV access. AddFastConsul() defaults to ConsulSettings and returns the service collection. Null services/configuration throw ArgumentNullException; an empty section name throws ArgumentException. Starting the host can register a service with Consul. Defaults are Enable=true, Address=http://127.0.0.1:8500, HealthCheck=/healthCheck, deregistration after 60 seconds of critical health, interval 10 seconds and timeout 5 seconds. Durations must be positive. ServiceAddress falls back to the listening address; configure a reachable address behind proxies. IKeyValueService is transient. GetKeyValue returns decoded text or deserializes T; missing keys throw KeyNotFoundException, invalid Base64 throws FormatException, and JSON failures propagate. EditKeyValue performs a remote write and returns Consul confirmation. There is no cancellation-token overload.
Installation and examples
Install the package
dotnet add package Fast.ConsulExample 1
using Fast.Consul;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFastConsul(builder.Configuration, "ConsulSettings");
var app = builder.Build();
app.MapGet("/healthCheck", () => "healthy");
app.Run();Example 2
using Fast.Consul;
public sealed class FeatureSettings
{
public bool EnablePreview { get; set; }
}
public sealed class FeatureReader(IKeyValueService values)
{
public Task<FeatureSettings> ReadAsync() =>
values.GetKeyValue<FeatureSettings>("sample/features", "dc1");
}Web-host examples belong in a consumer project using Microsoft.NET.Sdk.Web and a supported .NET target. IaaS examples can be used in an ordinary class library. Registration precedes builder.Build(); configure middleware and endpoints before app.Run(). Samples retain their original code and comments. No host, external service, database operation or client generator was run, and these snippets have not been compiled in this update.
