Lean  $LEAN_TAG$
QuantConnect.Util.Composer Class Reference

Provides methods for obtaining exported MEF instances More...

Public Member Functions

 Composer ()
 Initializes a new instance of the Composer class. This type is a light wrapper on top of an MEF CompositionContainer More...
 
Single< T > (Func< T, bool > predicate)
 Gets the export matching the predicate More...
 
void AddPart< T > (T instance)
 Adds the specified instance to this instance to allow it to be recalled via GetExportedValueByTypeName More...
 
GetPart< T > ()
 Gets the first type T instance if any More...
 
GetPart< T > (Func< T, bool > filter)
 Gets the first type T instance if any More...
 
IEnumerable< Type > GetExportedTypes< T > ()
 Will return all loaded types that are assignable to T type More...
 
GetExportedValueByTypeName< T > (string typeName, bool forceTypeNameOnExisting=true)
 Extension method to searches the composition container for an export that has a matching type name. This function will first try to match on Type.AssemblyQualifiedName, then Type.FullName, and finally on Type.Name More...
 
IEnumerable< T > GetExportedValues< T > ()
 Gets all exports of type T More...
 
void Reset ()
 Clears the cache of exported values, causing new instances to be created. More...
 

Static Public Attributes

static Composer Instance => LazyComposer.Value
 Gets the singleton instance More...
 

Detailed Description

Provides methods for obtaining exported MEF instances

Definition at line 38 of file Composer.cs.

Constructor & Destructor Documentation

◆ Composer()

QuantConnect.Util.Composer.Composer ( )

Initializes a new instance of the Composer class. This type is a light wrapper on top of an MEF CompositionContainer

Definition at line 60 of file Composer.cs.

Here is the call graph for this function:

Member Function Documentation

◆ Single< T >()

T QuantConnect.Util.Composer.Single< T > ( Func< T, bool >  predicate)

Gets the export matching the predicate

Parameters
predicateFunction used to pick which imported instance to return, if null the first instance is returned
Returns
The only export matching the specified predicate

Definition at line 169 of file Composer.cs.

◆ AddPart< T >()

void QuantConnect.Util.Composer.AddPart< T > ( instance)

Adds the specified instance to this instance to allow it to be recalled via GetExportedValueByTypeName

Template Parameters
TThe contract type
Parameters
instanceThe instance to add

Definition at line 184 of file Composer.cs.

◆ GetPart< T >() [1/2]

T QuantConnect.Util.Composer.GetPart< T > ( )

Gets the first type T instance if any

Template Parameters
TThe contract type

Definition at line 205 of file Composer.cs.

◆ GetPart< T >() [2/2]

T QuantConnect.Util.Composer.GetPart< T > ( Func< T, bool >  filter)

Gets the first type T instance if any

Template Parameters
TThe contract type

Definition at line 214 of file Composer.cs.

◆ GetExportedTypes< T >()

IEnumerable<Type> QuantConnect.Util.Composer.GetExportedTypes< T > ( )

Will return all loaded types that are assignable to T type

Type Constraints
T :class 

Definition at line 230 of file Composer.cs.

◆ GetExportedValueByTypeName< T >()

T QuantConnect.Util.Composer.GetExportedValueByTypeName< T > ( string  typeName,
bool  forceTypeNameOnExisting = true 
)

Extension method to searches the composition container for an export that has a matching type name. This function will first try to match on Type.AssemblyQualifiedName, then Type.FullName, and finally on Type.Name

This method will not throw if multiple types are found matching the name, it will just return the first one it finds.

Template Parameters
TThe type of the export
Parameters
typeNameThe name of the type to find. This can be an assembly qualified name, a full name, or just the type's name
forceTypeNameOnExistingWhen false, if any existing instance of type T is found, it will be returned even if type name doesn't match. This is useful in cases where a single global instance is desired, like for IDataAggregator
Returns
The export instance
Type Constraints
T :class 

Definition at line 257 of file Composer.cs.

Here is the call graph for this function:

◆ GetExportedValues< T >()

IEnumerable<T> QuantConnect.Util.Composer.GetExportedValues< T > ( )

Gets all exports of type T

Definition at line 368 of file Composer.cs.

Here is the call graph for this function:

◆ Reset()

void QuantConnect.Util.Composer.Reset ( )

Clears the cache of exported values, causing new instances to be created.

Definition at line 403 of file Composer.cs.

Here is the caller graph for this function:

Member Data Documentation

◆ Instance

Composer QuantConnect.Util.Composer.Instance => LazyComposer.Value
static

Gets the singleton instance

Intentionally using a property so that when its gotten it will trigger the lazy construction which will be after the right configuration is loaded. See GH issue 3258

Definition at line 54 of file Composer.cs.


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