Open sandboxFocus

Method RegisterService

RegisterService(Type, Func<object>)

Registers the factory of a service, or replaces the factory registered for the same type.

Declaration
public static void RegisterService(Type serviceType, Func<object> factory)
Parameters
Type Name Description
Type serviceType

The type of the service, as requested by the code that resolves it.

Func<object> factory

A delegate that returns the service. It runs each time the service is resolved, and must return an object assignable to serviceType.

RegisterService<T>(Func<T>)

Registers the factory of a service of type T, or replaces the factory registered for the same type.

Declaration
public static void RegisterService<T>(Func<T> factory)
Parameters
Type Name Description
Func<T> factory

A delegate that returns the service. It runs each time the service is resolved.

Type Parameters
Name Description
T

The type of the service, as requested by the code that resolves it.