Skip to content

)} )} )} )}

IMutableDependencyResolver.ServiceRegistrationCallback(Type, Action) method

Defined in

Type: IMutableDependencyResolver Namespace: Splat Assembly: Splat.Core.dll

Applies to

net11.0, net10.0, net47, net471, net472, net48, net481

Overloads

  1. IDisposable ServiceRegistrationCallback(Type serviceType, Action<IDisposable> callback)

  2. IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action<IDisposable> callback)

  3. IDisposable ServiceRegistrationCallback<T>(Action<IDisposable> callback)

  4. IDisposable ServiceRegistrationCallback<T>(string? contract, Action<IDisposable> callback)

1. Overload

IDisposable ServiceRegistrationCallback(Type serviceType, Action<IDisposable> callback)

Summary: Registers a callback to be invoked when a service of the specified type is registered or becomes available.

Parameters

NameTypeDescription
serviceTypeType (opens in a new tab)The type of the service to monitor for registration. Cannot be null.
callbackAction (opens in a new tab)The action to invoke when the service is registered. The callback receives an IDisposable representing the service registration. Cannot be null.

Returns: IDisposable (opens in a new tab) -- An IDisposable that can be used to unregister the callback.

2. Overload

IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action<IDisposable> callback)

Summary: Registers a callback to be invoked when a service of the specified type and contract is registered or unregistered.

Parameters

NameTypeDescription
serviceTypeType (opens in a new tab)The type of the service to monitor for registration events. Cannot be null.
contractstring? (opens in a new tab)An optional contract name that further qualifies the service type. May be null to match any contract.
callbackAction (opens in a new tab)An action to invoke when the service registration changes. The callback receives an IDisposable representing the registration. Cannot be null.

Returns: IDisposable (opens in a new tab) -- An IDisposable that can be disposed to unregister the callback.

Remarks

The callback is invoked whenever a matching service is registered or unregistered. Disposing the returned IDisposable will stop further notifications.

3. Overload

IDisposable ServiceRegistrationCallback<T>(Action<IDisposable> callback)

Summary: Registers a callback to be invoked when a service of type T is registered, and returns a disposable object that can be used to unregister the callback.

Type parameters

NameDescription
TThe type of the service to monitor for registration events.

Parameters

NameTypeDescription
callbackAction (opens in a new tab)The action to invoke when a service of type T is registered. The callback receives an IDisposable that can be used to unregister the callback.

Returns: IDisposable (opens in a new tab) -- An IDisposable that, when disposed, unregisters the callback.

4. Overload

IDisposable ServiceRegistrationCallback<T>(string? contract, Action<IDisposable> callback)

Summary: Registers a callback to be invoked when a service of type T is registered under the specified contract.

Type parameters

NameDescription
TThe type of the service to monitor for registration.

Parameters

NameTypeDescription
contractstring? (opens in a new tab)The contract name to filter service registrations. If null, the callback is invoked for all contracts.
callbackAction (opens in a new tab)The action to invoke when a matching service is registered. Receives an IDisposable that can be used to unregister the callback.

Returns: IDisposable (opens in a new tab) -- An IDisposable that, when disposed, unregisters the callback.

Remarks

Use this method to observe dynamic service registrations and perform actions when services become available. The callback is invoked each time a matching service is registered. Disposing the returned IDisposable will stop further notifications.