ServiceManager
Namespace Mc.Scripting.Services · Kind class (sealed)
public sealed class ServiceManagerPlugin-to-plugin services: a plugin registers an implementation of an interface (an economy, a chat formatter, a region lookup) and other plugins look it up without referencing the provider’s code. The interface type lives in the provider’s assembly or in a shared one; consumers declare depends / softDepends so the runtime resolves that assembly into their load context (the types then unify). Registrations are owned by the registering plugin and removed when it unloads, which fires ServiceManager.Changed so consumers drop their references.
Methods
Section titled “Methods”| Member | Description |
|---|---|
IDisposable Changed<T>(Action onChanged) where T : class |
Calls onChanged (on the tick thread) whenever the set of providers of T changes: a registration, an unregistration or a provider plugin unloading. |
T Get<T>() where T : class |
The highest-priority provider of T; throws ServiceUnavailableException when none is registered. |
IReadOnlyList<ServiceRegistration<T>> GetAll<T>() where T : class |
All registrations of T, best first. |
Register<T> |
Registers an implementation of T. |
T? TryGet<T>() where T : class |
The highest-priority provider of T, null when none is registered. |
bool Unregister<T>() where T : class |
Removes this plugin’s registration of T. |
Changed<T>
Section titled “Changed<T>”public IDisposable Changed<T>(Action onChanged) where T : classCalls onChanged (on the tick thread) whenever the set of providers of T changes: a registration, an unregistration or a provider plugin unloading. Use it to refresh a cached ServiceManager.TryGet result.
Type parameters
T: The service type.
Parameters
| Name | Type | Description |
|---|---|---|
onChanged |
Action |
The callback. |
Returns IDisposable: The subscription (disposed automatically when the plugin unloads).
Get<T>
Section titled “Get<T>”public T Get<T>() where T : classThe highest-priority provider of T; throws ServiceUnavailableException when none is registered.
Type parameters
T: The service type.
Returns T
GetAll<T>
Section titled “GetAll<T>”public IReadOnlyList<ServiceRegistration<T>> GetAll<T>() where T : classAll registrations of T, best first.
Type parameters
T: The service type.
Returns IReadOnlyList<ServiceRegistration<T>>
Register<T>
Section titled “Register<T>”public void Register<T>(T instance, ServicePriority priority = ServicePriority.Normal) where T : classRegisters an implementation of T.
Type parameters
T: The service interface (or class) consumers ask for.
Parameters
| Name | Type | Description |
|---|---|---|
instance |
T |
The implementation. |
priority |
ServicePriority = ServicePriority.Normal |
Its rank among several providers. |
TryGet<T>
Section titled “TryGet<T>”public T? TryGet<T>() where T : classThe highest-priority provider of T, null when none is registered. Thread-safe.
Type parameters
T: The service type.
Returns T?
Unregister<T>
Section titled “Unregister<T>”public bool Unregister<T>() where T : classRemoves this plugin’s registration of T.
Type parameters
T: The service type.
Returns bool: Whether a registration was removed.