Class FactoryExtensions
Provides extension methods to the IFactory class.
Inheritance
Namespace: Umbraco.Core
Assembly: Umbraco.Core.dll
Syntax
public static class FactoryExtensions
Methods
View SourceCreateInstance(IFactory, Type, Object[])
Creates an instance of a service, with arguments.
Declaration
public static object CreateInstance(this IFactory factory, Type type, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
IFactory | factory | |
System.Type | type | The type of the instance. |
System.Object[] | args | Named arguments. |
Returns
Type | Description |
---|---|
System.Object | An instance of the specified type. |
Remarks
The instance type does not need to be registered into the factory.
The arguments are used as dependencies by the factory. Other dependencies are retrieved from the factory.
CreateInstance<T>(IFactory, Object[])
Creates an instance with arguments.
Declaration
public static T CreateInstance<T>(this IFactory factory, params object[] args)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IFactory | factory | The factory. |
System.Object[] | args | Arguments. |
Returns
Type | Description |
---|---|
T | An instance of the specified type. |
Type Parameters
Name | Description |
---|---|
T | The type of the instance. |
Remarks
Throws an exception if the factory failed to get an instance of the specified type.
The arguments are used as dependencies by the factory.
GetInstance<T>(IFactory)
Gets an instance of a service.
Declaration
public static T GetInstance<T>(this IFactory factory)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IFactory | factory | The factory. |
Returns
Type | Description |
---|---|
T | An instance of the specified type. |
Type Parameters
Name | Description |
---|---|
T | The type of the service. |
Remarks
Throws an exception if the factory failed to get an instance of the specified type.
TryGetInstance<T>(IFactory)
Tries to get an instance of a service.
Declaration
public static T TryGetInstance<T>(this IFactory factory)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IFactory | factory |
Returns
Type | Description |
---|---|
T | An instance of the specified type, or null. |
Type Parameters
Name | Description |
---|---|
T | The type of the service. |
Remarks
Returns null if the factory does not know how to get an instance of the specified type. Throws an exception if the factory does know how to get an instance of the specified type, but failed to do so.