Class IInjectorBasicExtensions

Defines basic extensions for the IInjector interface.

Inheritance
System.Object
IInjectorBasicExtensions
Namespace: Solti.Utils.DI.Interfaces
Assembly: Solti.Utils.DI.Interfaces.dll
Syntax
public static class IInjectorBasicExtensions : Object

Methods

Get<TType>(IInjector, Object)

Gets the service instance associated with the given type and (optional) key:

IMyService svc = scope.Get<IMyService>();
Declaration
public static TType Get<TType>(this IInjector self, object key = null)
    where TType : class
Parameters
Type Name Description
IInjector self

The injector itself.

System.Object key

The (optional) service key.

Returns
Type Description
TType

The resolved service.

Type Parameters
Name Description
TType

The "id" of the service to be resolved.

Exceptions
Type Condition
ServiceNotFoundException

The service could not be found.

TryGet<TType>(IInjector, Object)

Tries to get the service instance associated with the given type and (optional) key:

IMyService? svc = scope.TryGet<IMyService>();
Declaration
public static TType TryGet<TType>(this IInjector self, object key = null)
    where TType : class
Parameters
Type Name Description
IInjector self

The injector itself.

System.Object key

The (optional) service key.

Returns
Type Description
TType

The requested service instance if the resolution was successful, null otherwise.

Type Parameters
Name Description
TType

The "id" of the service to be resolved.

In This Article
Back to top Generated by DocFX