Open sandboxFocus

Method GetRequiredService

GetRequiredService<T>()

Resolves a service of type T by running its factory, and throws an exception when no service is available.

Declaration
public static T GetRequiredService<T>()
Returns
Type Description
T

The service returned by the factory.

Type Parameters
Name Description
T

The type of the service.

Exceptions
Type Condition
InvalidOperationException

No service of type T is registered, or its factory returned null.

InvalidCastException

The factory returned an object that is not assignable to T.