An immutable implementation of IServiceProvider that will index services that implement the TBase
interface.
When a service is added to a ServiceProvider<TBase>, a mapping is created between the type of this object and the object itself,
but also between the type of any interface derived from TBase
and implemented by this object. Service provider instances
are immutable (each WithService(TBase, bool, bool) method
returns a copy of the service provider with the new service), except for the shared services, which are shared among all instances
of the same family.
Namespace: Metalama.Framework.Engine.Services
Assembly: Metalama.Framework.Sdk.dll
Syntax
public sealed class ServiceProvider<TBase> : ServiceProvider, IDisposable, IServiceProvider<TBase>, IServiceProvider where TBase : class
Type Parameters
Name | Description |
---|---|
TBase |
Properties
Name | Description |
---|---|
Empty |
Methods
Name | Description |
---|---|
AddSharedService(TBase) | |
AddSharedService<T>(Func<ServiceProvider<TBase>, T>) | |
Dispose() | |
GetService(Type) | Gets the implementation of a given service type. |
GetService<T>() | |
ToString() | |
TryGetService<T>(out T?) | Attempts to get a service if it has already been instantiated. |
WithDisjointSharedServices() | Returns a ServiceProvider<TBase> that has different shared services than the current ServiceProvider<TBase>. The new ServiceProvider<TBase> inherits all shared services of the current one, but adding a new shared service to the new instance will not affect the old instance, and adding services to the old instance will not affect the new one. |
WithService(TBase, bool, bool) | Returns a new ServiceProvider<TBase> where a service have been added to the current ServiceProvider<TBase>. If the new service is already present in the current ServiceProvider<TBase>, it is replaced in the new ServiceProvider<TBase>. |
WithServiceConditional<T>(Func<ServiceProvider<TBase>, T>, bool) | |
WithService<T>(Func<ServiceProvider<TBase>, T>, bool, bool) | |
WithServices(IEnumerable<TBase>?, bool) | Returns a new ServiceProvider<TBase> where some given services have been added to the current ServiceProvider<TBase>. If some of the new services are already present in the current ServiceProvider<TBase>, they are replaced in the new ServiceProvider<TBase>. |
WithServices(TBase, TBase, params TBase[]) | Returns a new ServiceProvider<TBase> where some given services have been added to the current ServiceProvider<TBase>. If some of the new services are already present in the current ServiceProvider<TBase>, they are replaced in the new ServiceProvider<TBase>. |
WithUntypedService(Type, object, bool) |