ConnectionResolver

Helper class used to retrieve component connections.

Description

The ConnectionResolver class is used to retrieve component connections.

Important points

  • If the connections are configured to be retrieved from IDiscovery, the connection resolver will automatically locate IDiscovery in component references and retrieve the connections from there using the discovery_key parameter.

Configuration parameters

connection:

  • discovery_key: (optional) key to retrieve the connection from IDiscovery
  • : other connection parameters

connections: alternative to connection

  • [connection params 1]: first connection parameters
    • : connection parameters for key 1
  • [connection params N]: Nth connection parameters
    • : connection parameters for key N

References

  • *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve connections

Constructors

Creates a new instance of this class.

public ConnectionResolver(ConfigParams config = null, IReferences references = null)

  • config: ConfigParams - (optional) component’s configuration parameters
  • references: IReferences - (optional) component’s references

Instance methods

Add

Adds a new connection.

public void Add(ConnectionParams connection)

Configure

Configures the component by passing its configuration parameters.

public void Configure(config: ConfigParams)

  • config: ConfigParams - configuration parameters to be set.

GetAll

Gets all connections configured in component configuration. Redirect to Discovery services is not done at this point. If you need a fully fleshed connection, use Resolve method instead.

public List<ConnectionParams> GetAll()

RegisterAsync

Registers the given connection in all referenced discovery services. This method can be used for dynamic service discovery.

public Task<void> RegisterAsync(IContext context, ConnectionParams connection)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • connection: ConnectionParams - connection to register.

ResolveAsync

Resolves a single component connection. If connections are configured to be retrieved from Discovery service, it finds a IDiscovery and resolves the connection there.

public Task<ConnectionParams> ResolveAsync(IContext context)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • returns: Task<ConnectionParams> - resolved connection parameters or null if nothing was found.

ResolveAllAsync

Resolves all component connection. If connections are configured to be retrieved from Discovery service, it finds a IDiscovery and resolves the connection there.

public Task<List<ConnectionParams>> ResolveAllAsync(IContext context)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • returns: Task<List<ConnectionParams>> - list of resolved connections.

SetReferences

Sets references to dependent components.

public void SetReferences(IReferences references)

  • references: IReferences - references to locate the component’s dependencies.

Examples

var config = ConfigParams.FromTuples(
    "connection.host", "10.1.1.100",
    "connection.port", 8080
);

var connectionResolver = new ConnectionResolver();
connectionResolver.Configure(config);
connectionResolver.SetReferences(references);
connectionResolver.ResolveAsync("123");

See also