A lightweight .NET library for validating microservice dependencies during application startup. The library ensures that all required services are available before the main application begins its operation.
Supported frameworks: .NET 6, .NET 7, .NET 8, .NET 9, .NET 10
- Asynchronous health checks for HTTP/HTTPS endpoints
- Configurable retry policies with customizable timeouts
- Support for custom port configurations
- Built-in logging for dependency validation process
- Cancellation support for health check operations
Designed to prevent application startup failures due to unavailable dependencies by implementing a readiness probe pattern for microservice environments.
Install the Cross.WebHost.AvailabilityCheck NuGet package into your ASP.NET Core project:
Install-Package Cross.WebHost.AvailabilityCheckor
dotnet add package Cross.WebHost.AvailabilityCheckAdd service availability check in your Program.cs or Startup.cs:
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// ...
var app = builder.Build();
// ...
// Configure service hosts to check
var hostsToCheck = new[]
{
"CheckServiceUrls:AuthService",
"CheckServiceUrls:UserService"
};
// Add availability check
AvailabilityHostsConfiguration.ConfigureAvailabilityHosts(
hostsToCheck,
builder.Configuration,
app.Logger,
timeoutInMs: 1500, // (Optional) Default: 1000 ms.
maxAttempts: 100 // (Optional) Default: 50 times.
);
app.Run();
}
}{
"CheckServiceUrls": {
"AuthService": "https://auth-service:5001",
"UserService": "http://user-service:5002"
}
}The library supports various URL formats:
- HTTP URLs:
http://service-name:80 - HTTPS URLs:
https://service-name:443 - HTTP Default ports:
http://service-name(assumes port 80) - HTTPS Default ports:
https://service-name(assumes port 443) - Custom ports:
service-name:5000 - IP addresses:
192.168.1.100:5000
The library uses standard .NET logging mechanisms. Configure logging level in your appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Cross.WebHost.AvailabilityCheck": "Debug"
}
}
}Run unit tests:
dotnet test Cross.WebHost.AvailabilityCheck.Tests/Cross.WebHost.AvailabilityCheck.Tests.csprojRun unit tests with OpenCover coverage:
dotnet test Cross.WebHost.AvailabilityCheck.Tests/Cross.WebHost.AvailabilityCheck.Tests.csproj \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencoverContribution is welcomed. If you would like to provide a PR please add some testing.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.