Pip-Services-Commons-Dotnet
Public Member Functions | List of all members
PipServices3.Commons.Refer.IReferences Interface Reference

Interface for a map that holds component references and passes them to components to establish dependencies with each other. More...

Inheritance diagram for PipServices3.Commons.Refer.IReferences:
PipServices3.Commons.Refer.References

Public Member Functions

void Put (object locator, object component)
 Puts a new component reference to the set with explicit locator More...
 
object Remove (object locator)
 Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one.When all references shall be removed, use removeAll() method instead. More...
 
List< object > RemoveAll (object locator)
 Removes all component references that match the specified locator. More...
 
List< object > GetAllLocators ()
 Gets locators for all registered component references in this reference map. More...
 
List< object > GetAll ()
 Gets all component references registered in this reference map. More...
 
List< object > GetOptional (object locator)
 Gets all component references that match specified locator. More...
 
List< T > GetOptional< T > (object locator)
 Gets all component references that match specified locator and matching to the specified type. More...
 
List< object > GetRequired (object locator)
 Gets all component references that match specified locator. At least one component reference must be present.If it doesn't the method throws an error. More...
 
List< T > GetRequired< T > (object locator)
 Gets all component references that match specified locator. At least one component reference must be present and matching to the specified type. More...
 
object GetOneOptional (object locator)
 Gets an optional component reference that matches specified locator. More...
 
GetOneOptional< T > (object locator)
 Gets an optional component reference that matches specified locator and matching to the specified type. More...
 
object GetOneRequired (object locator)
 Gets a required component reference that matches specified locator. More...
 
GetOneRequired< T > (object locator)
 Gets a required component reference that matches specified locator and matching to the specified type. More...
 
List< object > Find (object locator, bool required)
 Gets all component references that match specified locator. More...
 
List< T > Find< T > (object locator, bool required)
 Gets all component references that match specified locator and matching to the specified type. More...
 

Detailed Description

Interface for a map that holds component references and passes them to components to establish dependencies with each other.

Together with IReferenceable and IUnreferenceable interfaces it implements a Locator pattern that is used by PipServices toolkit for Inversion of Control to assign external dependencies to components.

The IReferences object is a simple map, where keys are locators and values are component references.It allows to add, remove and find components by their locators.Locators can be any values like integers, strings or component types. But most often PipServices toolkit uses Descriptor as locators that match by 5 fields: group, type, kind, name and version.

public class MyController: IReferenceable
{
public IMyPersistence _persistence;
...
public void SetReferences(IReferences references)
{
this._persistence = references.getOneRequired<IMyPersistence>(
new Descriptor("mygroup", "persistence", "*", "*", "1.0")
);
}
...
}
var persistence = new MyMongoDbPersistence();
var controller = new MyController();
var references = References.FromTuples(
new Descriptor("mygroup", "persistence", "mongodb", "default", "1.0"), persistence,
new Descriptor("mygroup", "controller", "default", "default", "1.0"), controller );
controller.SetReferences(references);

See Descriptor, References

Member Function Documentation

◆ Find()

List<object> PipServices3.Commons.Refer.IReferences.Find ( object  locator,
bool  required 
)

Gets all component references that match specified locator.

Parameters
locatorthe locator to find a reference by.
requiredforces to raise exception is no reference is found
Returns
a list with matching component references.

Implemented in PipServices3.Commons.Refer.References.

◆ Find< T >()

List<T> PipServices3.Commons.Refer.IReferences.Find< T > ( object  locator,
bool  required 
)

Gets all component references that match specified locator and matching to the specified type.

Template Parameters
Tthe class type
Parameters
locatorthe locator to find a reference by.
requiredforces to raise exception is no reference is found
Returns
a list with matching component references.

Implemented in PipServices3.Commons.Refer.References.

◆ GetAll()

List<object> PipServices3.Commons.Refer.IReferences.GetAll ( )

Gets all component references registered in this reference map.

Returns
a list with component references

Implemented in PipServices3.Commons.Refer.References.

◆ GetAllLocators()

List<object> PipServices3.Commons.Refer.IReferences.GetAllLocators ( )

Gets locators for all registered component references in this reference map.

Returns
a list with component locators

Implemented in PipServices3.Commons.Refer.References.

◆ GetOneOptional()

object PipServices3.Commons.Refer.IReferences.GetOneOptional ( object  locator)

Gets an optional component reference that matches specified locator.

Parameters
locatora locator to find a reference
Returns
a found component reference or
null
if nothing was found

Implemented in PipServices3.Commons.Refer.References.

◆ GetOneOptional< T >()

Gets an optional component reference that matches specified locator and matching to the specified type.

Template Parameters
Tthe class type
Parameters
locatora locator to find a reference
Returns
a found component reference or
null
if nothing was found

Implemented in PipServices3.Commons.Refer.References.

◆ GetOneRequired()

object PipServices3.Commons.Refer.IReferences.GetOneRequired ( object  locator)

Gets a required component reference that matches specified locator.

Parameters
locatora locator to find a reference
Returns
a matching component reference.

Implemented in PipServices3.Commons.Refer.References.

◆ GetOneRequired< T >()

Gets a required component reference that matches specified locator and matching to the specified type.

Template Parameters
Tthe class type
Parameters
locatora locator to find a reference
Returns
a found component reference

Implemented in PipServices3.Commons.Refer.References.

◆ GetOptional()

List<object> PipServices3.Commons.Refer.IReferences.GetOptional ( object  locator)

Gets all component references that match specified locator.

Parameters
locatora locator to find references by
Returns
a list with matching component references or empty list if nothing was found.

Implemented in PipServices3.Commons.Refer.References.

◆ GetOptional< T >()

List<T> PipServices3.Commons.Refer.IReferences.GetOptional< T > ( object  locator)

Gets all component references that match specified locator and matching to the specified type.

Template Parameters
Tthe class type
Parameters
locatorthe locator to find references by.
Returns
a list with matching component references or empty list if nothing was found.

Implemented in PipServices3.Commons.Refer.References.

◆ GetRequired()

List<object> PipServices3.Commons.Refer.IReferences.GetRequired ( object  locator)

Gets all component references that match specified locator. At least one component reference must be present.If it doesn't the method throws an error.

Parameters
locatora locator to find references
Returns
a list with found component references

Implemented in PipServices3.Commons.Refer.References.

◆ GetRequired< T >()

List<T> PipServices3.Commons.Refer.IReferences.GetRequired< T > ( object  locator)

Gets all component references that match specified locator. At least one component reference must be present and matching to the specified type.

If it doesn't the method throws an error.

Template Parameters
Tthe class type
Parameters
locatora locator to find references
Returns
a list with found component references

Implemented in PipServices3.Commons.Refer.References.

◆ Put()

void PipServices3.Commons.Refer.IReferences.Put ( object  locator,
object  component 
)

Puts a new component reference to the set with explicit locator

Parameters
locatora locator to find the reference by
componenta component reference to be added

Implemented in PipServices3.Commons.Refer.References.

◆ Remove()

object PipServices3.Commons.Refer.IReferences.Remove ( object  locator)

Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one.When all references shall be removed, use removeAll() method instead.

Parameters
locatora locator to find the reference to remove
Returns
a removed component reference

See RemoveAll(object)

Implemented in PipServices3.Commons.Refer.References.

◆ RemoveAll()

List<object> PipServices3.Commons.Refer.IReferences.RemoveAll ( object  locator)

Removes all component references that match the specified locator.

Parameters
locatora locator to remove the reference by
Returns
a list, containing all removed references.

Implemented in PipServices3.Commons.Refer.References.


The documentation for this interface was generated from the following file: