Skip to content

)} )} )} )}

IMutableDependencyResolver.ServiceRegistrationCallback(Type, Action) method

Defined in

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

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, 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
serviceTypeTypeThe type of the service to monitor for registration. Cannot be null.
callbackActionThe action to invoke when the service is registered. The callback receives an IDisposable representing the service registration. Cannot be null.

Returns: IDisposable -- 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
serviceTypeTypeThe type of the service to monitor for registration events. Cannot be null.
contractstring?An optional contract name that further qualifies the service type. May be null to match any contract.
callbackActionAn action to invoke when the service registration changes. The callback receives an IDisposable representing the registration. Cannot be null.

Returns: IDisposable -- 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
callbackActionThe 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 -- 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?The contract name to filter service registrations. If null, the callback is invoked for all contracts.
callbackActionThe action to invoke when a matching service is registered. Receives an IDisposable that can be used to unregister the callback.

Returns: IDisposable -- 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.