ConsulServiceRegisterAndDiscovery 1.0.0

dotnet add package ConsulServiceRegisterAndDiscovery --version 1.0.0
NuGet\Install-Package ConsulServiceRegisterAndDiscovery -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConsulServiceRegisterAndDiscovery" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConsulServiceRegisterAndDiscovery --version 1.0.0
#r "nuget: ConsulServiceRegisterAndDiscovery, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ConsulServiceRegisterAndDiscovery as a Cake Addin
#addin nuget:?package=ConsulServiceRegisterAndDiscovery&version=1.0.0

// Install ConsulServiceRegisterAndDiscovery as a Cake Tool
#tool nuget:?package=ConsulServiceRegisterAndDiscovery&version=1.0.0

Sample Code

Only Use Service Register
//AddConsulClient use default consul config;(ConsulScheme="http",ConsulHost="localhost",ConsulPort=8500)
// you can also use your config by call another overload function.
builder.Services.AddConsulClient();

//Register current service into Consul
var serviceUri = new UriBuilder(builder.Configuration["urls"]);
var consulRegisterInfo = new ConsulRegiterInfoModel()
{
    ConsulServiceName = "Grpc",
    CurrentAppHost = serviceUri.Host,
    CurrentAppPort = serviceUri.Port
};
app.RegisterConsul(consulRegisterInfo);
Use Service provider

after add the ConsuleClient you should add the follow code

//the first param is the servicename which you want to register into the consul.
//the second param is the Scheme of the registed service.
builder.Services.AddConsulServiceProvider("Grpc", "http");

then you can use the service discovery like this(the service provider work with polling load balance):


    public class DemoService
    {
        private readonly IConsulServiceProvider _consulServiceProvider;
        public DemoService(IConsulServiceProvider consulServiceProvider)
        {
            _consulServiceProvider = consulServiceProvider;
        }
    }

Health Check
var serviceUri = new UriBuilder(builder.Configuration["urls"]);
var consulRegisterInfo = new ConsulRegiterInfoModel()
{
    ConsulServiceName = "WebApi",
    CurrentAppHost = serviceUri.Host,
    CurrentAppPort = serviceUri.Port,
    //Normal RESTful api url for health check
    CurrentAppHealthCheckUrl = $"{serviceUri.Uri.AbsoluteUri}api/Health/HealthCheck",
    //Grpc health check
    GRPC = serviceUri.Uri.Authority
};
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 205 4/28/2022

First Release.