Pip-Services-Commons-Dotnet
|
Helper class for resolving component dependencies. More...
Public Member Functions | |
DependencyResolver () | |
Creates a new instance of the dependency resolver. More... | |
DependencyResolver (ConfigParams config) | |
Creates a new instance of the dependency resolver. More... | |
void | Configure (ConfigParams config) |
Configures the component with specified parameters. More... | |
void | SetReferences (IReferences references) |
Sets the component references More... | |
void | Put (string name, object locator) |
Adds a new dependency into this resolver. More... | |
List< object > | GetOptional (string name) |
Gets all optional dependencies by their name. More... | |
List< T > | GetOptional< T > (string name) |
Gets all optional dependencies by their name. More... | |
List< object > | GetRequired (string name) |
Gets all required dependencies by their name. At least one dependency must present.If no dependencies was found it throws a ReferenceException More... | |
List< T > | GetRequired< T > (string name) |
Gets all required dependencies by their name. At least one dependency must present.If no dependencies was found it throws a ReferenceException More... | |
object | GetOneOptional (string name) |
Gets one optional dependency by its name. More... | |
T | GetOneOptional< T > (string name) |
Gets one optional dependency by its name and matching to the specified type. More... | |
object | GetOneRequired (string name) |
Gets one required dependency by its name. At least one dependency must present.If the dependency was found it throws a ReferenceException More... | |
T | GetOneRequired< T > (string name) |
Gets one required dependency by its name and matching to the specified type. At least one dependency must present.If the dependency was found it throws a ReferenceException More... | |
List< object > | Find (string name, bool required) |
Finds all matching dependencies by their name. More... | |
List< T > | Find< T > (string name, bool required) |
Finds all matching dependencies by their name and matching to the specified type. More... | |
Static Public Member Functions | |
static DependencyResolver | FromTuples (params object[] tuples) |
Creates a new DependencyResolver from a list of key-value pairs called tuples where key is dependency name and value the depedency locator(descriptor). More... | |
Private Member Functions | |
object | Locate (string name) |
Gets a dependency locator by its name. More... | |
Private Attributes | |
Dictionary< string, object > | _dependencies = new Dictionary<string, object>() |
IReferences | _references |
Helper class for resolving component dependencies.
The resolver is configured to resolve named dependencies by specific locator. During deployment the dependency locator can be changed.
This mechanism can be used to clarify specific dependency among several alternatives. Typically components are configured to retrieve the first dependency that matches logical group, type and version.But if container contains more than one instance and resolution has to be specific about those instances, they can be given a unique name and dependency resolvers can be reconfigured to retrieve dependencies by their name.
Configuration parameters:
dependencies:
See IReferences
PipServices3.Commons.Refer.DependencyResolver.DependencyResolver | ( | ) |
Creates a new instance of the dependency resolver.
PipServices3.Commons.Refer.DependencyResolver.DependencyResolver | ( | ConfigParams | config | ) |
Creates a new instance of the dependency resolver.
config | (optional) default configuration where key is dependency name and value is locator(descriptor) |
See ConfigParams, Configure(ConfigParams), IReferences, SetReferences(IReferences)
void PipServices3.Commons.Refer.DependencyResolver.Configure | ( | ConfigParams | config | ) |
Configures the component with specified parameters.
config | configuration parameters to set. |
See ConfigParams
Implements PipServices3.Commons.Config.IConfigurable.
List<object> PipServices3.Commons.Refer.DependencyResolver.Find | ( | string | name, |
bool | required | ||
) |
Finds all matching dependencies by their name.
name | the dependency name to locate. |
required | true to raise an exception when no dependencies are found. |
List<T> PipServices3.Commons.Refer.DependencyResolver.Find< T > | ( | string | name, |
bool | required | ||
) |
Finds all matching dependencies by their name and matching to the specified type.
T | the class type |
name | the dependency name to locate. |
required | true to raise an exception when no dependencies are found. |
|
static |
Creates a new DependencyResolver from a list of key-value pairs called tuples where key is dependency name and value the depedency locator(descriptor).
tuples | a list of values where odd elements are dependency name and the following even elements are dependency locator(descriptor) |
object PipServices3.Commons.Refer.DependencyResolver.GetOneOptional | ( | string | name | ) |
Gets one optional dependency by its name.
name | the dependency name to locate. |
T PipServices3.Commons.Refer.DependencyResolver.GetOneOptional< T > | ( | string | name | ) |
Gets one optional dependency by its name and matching to the specified type.
T | the class type |
name | the dependency name to locate. |
object PipServices3.Commons.Refer.DependencyResolver.GetOneRequired | ( | string | name | ) |
Gets one required dependency by its name. At least one dependency must present.If the dependency was found it throws a ReferenceException
name | the dependency name to locate. |
T PipServices3.Commons.Refer.DependencyResolver.GetOneRequired< T > | ( | string | name | ) |
Gets one required dependency by its name and matching to the specified type. At least one dependency must present.If the dependency was found it throws a ReferenceException
T | the class type |
name | the dependency name to locate. |
List<object> PipServices3.Commons.Refer.DependencyResolver.GetOptional | ( | string | name | ) |
Gets all optional dependencies by their name.
name | the dependency name to locate. |
List<T> PipServices3.Commons.Refer.DependencyResolver.GetOptional< T > | ( | string | name | ) |
Gets all optional dependencies by their name.
T | the class type |
name | the dependency name to locate. |
List<object> PipServices3.Commons.Refer.DependencyResolver.GetRequired | ( | string | name | ) |
Gets all required dependencies by their name. At least one dependency must present.If no dependencies was found it throws a ReferenceException
name | the dependency name to locate. |
List<T> PipServices3.Commons.Refer.DependencyResolver.GetRequired< T > | ( | string | name | ) |
Gets all required dependencies by their name. At least one dependency must present.If no dependencies was found it throws a ReferenceException
T | the class type |
name | the dependency name to locate. |
|
private |
Gets a dependency locator by its name.
name | the name of the dependency to locate. |
void PipServices3.Commons.Refer.DependencyResolver.Put | ( | string | name, |
object | locator | ||
) |
Adds a new dependency into this resolver.
name | the dependency's name. |
locator | the locator to find the dependency by. |
void PipServices3.Commons.Refer.DependencyResolver.SetReferences | ( | IReferences | references | ) |
Sets the component references
references | references to set. |
Implements PipServices3.Commons.Refer.IReferenceable.