Provides a base implementation for managing services within an application. Implements the IServiceRegistry interface.
public class ServiceRegistry : IServiceRegistry
- Extension Methods
This class uses a dictionary to store services by their types. It is thread-safe.
The key used to identify the ServiceRegistry instance.
public static readonly PropertyKey<IServiceRegistry> ServiceRegistryKey
Adds a service to this ServiceRegistry.
public void AddService<T>(T service) where T : class
The service to add.
The type of service to add.
This implementation triggers the ServiceAdded event after a service is successfully added.
Thrown when the provided service is null.
Thrown when a service of the same type is already registered.
Gets the service object of the specified type.
public T GetService<T>() where T : class
A service of the requested type, or [null] if not found.
The type of the service to retrieve.
Removes the object providing a specified service.
public void RemoveService<T>() where T : class
The type of the service to remove.
This implementation triggers the ServiceRemoved event after a service is successfully removed. If the service type is not found, this method does nothing.
Occurs when a new service is added to the registry.
public event EventHandler<ServiceEventArgs> ServiceAdded
Occurs when a service is removed from the registry.
public event EventHandler<ServiceEventArgs> ServiceRemoved