Resolves object dependencies that are discovered during dependency injection
with the help of a service locator, a resource locator, and a built in set of conversions.
Namespace:
Gallio.Runtime.ExtensibilityAssembly: Gallio (in Gallio.dll) Version: 3.2.0.0 (3.2.356.0)
Syntax
| C# |
|---|
public class DefaultObjectDependencyResolver : IObjectDependencyResolver |
| Visual Basic (Declaration) |
|---|
Public Class DefaultObjectDependencyResolver _ Implements IObjectDependencyResolver |
Remarks
To resolve dependencies, the object dependency resolver applies the following rules:
- If a configuration argument value was provided then it is converted to an instance of the parameter type (see below).
- If the service locator can resolve a service of the parameter type, or if the parameter type is an array and the service locator can resolve one or more services of the array's element type, then those services will be resolved and injected.
- If the parameter type is ComponentHandle<(Of <(TService, TTraits>)>) or an array of that type and the service locator can resolve an a service of the requested type, then the associated services will be resolve and injected as component handles.
To convert string configuration arguments to the parameter type, the object factory applies the following rules:
- If the parameter type is an array type, then the configuration argument is split on semicolons (';') and each part is independently converted to a value of the array's element type and then packaged into an array.
- If the parameter type is a string, then no conversion is required so the value is used as-is.
- If the value looks like "${component.id}" and there is a component registered with the specified component id that satisfies the service described by the parameter type then that component is injected. Similarly if the parameter is of type ComponentHandle<(Of <(TService, TTraits>)>) and the component implements the requested service type then a handle of that component is injected.
- If the parameter type is an enum then the value is parsed to a value of that enum type, case-insensitively.
- If the parameter type is Version then the value is parsed into a version.
- If the parameter type is Guid then the value is parsed into a guid.
- If the parameter type is Condition then the value is parsed into a condition.
- If the parameter type is Image then the value is treated as a Uri to a resource and the image is loaded from the resource locator.
- If the parameter type is Icon then the value is treated as a Uri to a resource and the icon is loaded from the resource locator.
- If the parameter type is FileInfo or DirectoryInfo then the value is treated as a Uri to a file or directory resource and an instance of the appropriate file/directory info type is injected using the full path obtained from the resource locator.
- If the parameter type is Assembly then the value is interpreted the name of an assembly which is loaded using Load(String).
- If the parameter type is Type then the value is interpereted as the assembly-qualified name of a type which is obtained using GetType(String).
- If the parameter type is AssemblyName then the value is parsed into an assembly name.
- If the parameter type is AssemblySignature then the value is parsed into an assembly signature.
- Otherwise, the value is converted using ChangeType(Object, Type) if possible.
For information about how the Uri is resolved to a path, see ResolveResourcePath(Uri).
