Inherits: IConfigurable, IReferenceable, IOpenable
Description
The DirectClientclass allows you to create clients that call a controller directly in the same memory space.
Important points
- It is used when multiple microservices are deployed in a single container (monolyth) and communication between them can be done by direct calls rather than through the network.
 
Configuration parameters
- dependencies:
- controller: override controller descriptor
 
 
References
- *:logger:*:*:1.0 - (optional) ILogger components to pass log messages
 - *:counters:*:*:1.0 - (optional) ICounters components to pass collected measurements
 - *:traces:*:*:1.0 - (optional) ITracer components to record traces
 - *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve a connection
 
Fields
Instance methods
CloseAsync
Closes a component and frees used resources.
public virtualTask CloseAsync(IContext context)
- context: IContext - (optional) a context to trace execution through a call chain.
 
Configure
Configures component by passing its configuration parameters.
public virtualvoid Configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
 
Instrument
Adds instrumentation to log calls and measures call time. It returns a Timing object that is used to end the time measurement.
protectedCounterTiming Instrument(IContext context, [CallerMemberName]string methodName = null)
- context: IContext - (optional) a context to trace execution through a call chain.
 - methodName: [CallerMemberName]string - method name.
 - returns: CounterTiming - CounterTiming object used to end the time measurement.
 
InstrumentError
Adds instrumentation to error handling.
protectedvoid InstrumentError(IContext context, [CallerMemberName]string methodName = null, Exception ex = null, bool rethrow = false)
- context: IContext - (optional) a context to trace execution through a call chain.
 - methodName: [CallerMemberName]string - method name.
 - ex: Exception - error that occured during the method call.
 - rethrow: bool - true to throw the exception.
 
IsOpen
Checks if the component is open.
public virtualbool IsOpen()
- returns: bool - true if the component is open and false otherwise.
 
OpenAsync
Opens the component.
public virtualTask OpenAsync(IContext context)
- context: IContext - (optional) a context to trace execution through a call chain.
 
SetReferences
Sets references to dependent components.
public virtualvoid SetReferences(IReferences references)
- references: IReferences - references to locate the component’s dependencies.
 
Examples
class MyDirectClient: DirectClient<IMyController>, IMyClient 
{
    public MyDirectClient()
    {   
        base();
        this._dependencyResolver.put("controller", new Descriptor("mygroup", "controller", "*", "*", "*"));
    }
    ...
    
    public MyData GetData(IContext context, string id)
    {
        var timing = this.Instrument(context, 'myclient.get_data');
        var result = this._controller.GetData(context, id);
        timing.EndTiming();
        return result;
    }
    ...
}
var client = new MyDirectClient();
client.SetReferences(References.FromTuples(
    new Descriptor("mygroup","controller","default","default","1.0"), controller)
);
var data = client.GetData("123", "1");
...