ServiceRegistry is a combination of middleware and services. All configuration is done in your startup class.
You add the ServiceRegistry services to the DI system by calling:
public void ConfigureServices(IServiceCollection services)
{
services.AddServiceRegistry();
}
public void Configure(IApplicationBuilder app)
{
...
app.UseServiceRegistry();
...
app.UseMvc();
}Optionally you can pass in options into this call.
This will return you a builder object that in turn has a number of convenience methods to wire up additional services.
The "in-memory" configuration APIs allow for configuring ServiceRegistry from an in-memory list of configuration objects.
Use of these configuration APIs are designed for use when prototyping, developing, and/or testing where it is not necessary to dynamically consult database at runtime for the configuration data.
AddInMemoryStoreRegistersIServiceStoreimplementation storing services as in-memory list. Optional arguments are services which will be added to the store.
public void ConfigureServices(IServiceCollection services)
{
services.AddServiceRegistry()
.AddInMemoryStore();
}Available persistence libraries are:
Use one of the following extension method to register your custom store:
AddServiceStoreAddsIServiceStoreimplementation for reading and storing services.
Service configuration data is used frequently by ServiceRegistry. If this data is being loaded from a database or other external store, then it might be expensive to frequently re-load the same data.
-
AddInMemoryCachingTo use any of the caches described below, an implementation ofICache<T>must be registered in DI. This API registers a default in-memory implementation ofICache<T>that's based on ASP.NET Core'sMemoryCache. -
AddServiceStoreCacheRegisters aIServiceStoredecorator implementation which will maintain an in-memory cache ofServiceconfiguration objects. The cache duration is configurable on theCachingconfiguration options on theServiceRegistryOptions.
Further customization of the cache is possible:
The default caching relies upon the ICache<T> implementation.
If you wish to customize the caching behavior for the specific configuration objects, you can replace this implementation in the dependency injection system.
The default implementation of the ICache<T> itself relies upon the IMemoryCache interface (and MemoryCache implementation) provided by .NET.
If you wish to customize the in-memory caching behavior, you can replace the IMemoryCache implementation in the dependency injection system.
There's no built-in UI to show the registered services. It's fairly easy to build one by yourself using the IServiceRegistry. Please have a look at the sample.
Following APIs are provided by this library:
This endpoint registers a service in the registry.
| Url | Method | Type |
|---|---|---|
| /v1/register | POST | application/json |
{
"serviceId": "UniqueServiceId", //required
"displayName": "A human friendly display name",
"endpoints": ["https://myservice01-qa.com"], //required
"ipAddress": "10.10.0.1",
"publicUrls": ["https://myserviceurl-qa.com"]
}text/plain HTTP 200
The endpoint returns a token which should be used to unregister the service.
This endpoint removes a service registration.
| Url | Method | Type |
|---|---|---|
| /v1/register | DELETE | text/plain |
The token returned from the service registration call.
dfg54dfg54df3g21df53g4df3g54
text/plain HTTP 200
This endpoint returns the registered service.
| Url | Method | Type |
|---|---|---|
| /v1/service/{serviceId} | Get |
serviceid The service you want to retrieve
application/json HTTP 200
The endpoint returns the registered service.
If no public url was registered, the endpoints will be published as public urls.
{
"serviceId": "UniqueServiceId",
"displayName": "A human friendly display name",
"endpoints": ["http://myserviceurl01.com", "http://myserviceurl02.com"],
"ipAddresses": ["10.10.0.1", "10.10.0.2"],
"publicUrls": ["https://myserviceurl.com"]
}This endpoint returns all registered services.
| Url | Method | Type |
|---|---|---|
| /v1/service | Get |
application/json HTTP 200
The endpoint returns all registered services.
[
{
"serviceId": "UniqueServiceId",
"displayName": "A human friendly display name",
"serviceEndpoints": ["http://myserviceurl01.com", "http://myserviceurl02.com"],
"ipAddresses": ["10.10.0.1", "10.10.0.2"],
"publicUrls": ["https://myserviceurl.com"]
},
{
...
}
]