Files

61 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- Common/DTS.Common.Core/ServiceManager/IServicePublishedEvent.cs
- Common/DTS.Common.Core/ServiceManager/ServicePublishedEvent.cs
- Common/DTS.Common.Core/ServiceManager/ServiceManager.cs
generated_at: "2026-04-17T16:35:08.366069+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "97facc88d83d9155"
---
# ServiceManager Module Documentation
## 1. Purpose
The ServiceManager module provides a service locator pattern implementation that enables loose coupling between components. It allows a component to publish an implementation of a singleton interface (service) that other components can retrieve without knowing the publisher. The module includes an event system (`IServicePublishedEvent`/`ServicePublishedEvent`) that notifies subscribers when services are published or unpublished, enabling reactive dependency management across the application.
---
## 2. Public Interface
### `IServicePublishedEvent` (interface)
**File:** `IServicePublishedEvent.cs`
Event contract fired when a service interface is published or unpublished.
| Property | Type | Description |
|----------|------|-------------|
| `ServiceType` | `Type` | Returns the type of service being published/unpublished. |
| `IsPublished` | `bool` | Returns `true` if the service is being published, `false` if being unpublished. |
---
### `ServicePublishedEvent` (class)
**File:** `ServicePublishedEvent.cs`
Concrete implementation of `IServicePublishedEvent`.
| Property | Type | Accessor | Description |
|----------|------|----------|-------------|
| `ServiceType` | `Type` | `get; internal set;` | The type of service being published/unpublished. |
| `IsPublished` | `bool` | `get; internal set;` | `true` if publishing, `false` if unpublishing. |
---
### `ServiceManager` (static class)
**File:** `ServiceManager.cs`
Static service locator that manages publication and retrieval of singleton services.
#### Methods
| Signature | Description |
|-----------|-------------|
| `void Publish<T>(T item) where T : class` | Publishes a service implementation for interface type `T`. Throws `ArgumentException` if `T` is already published. |
| `void Publish(object item, IEnumerable<Type> interfaceList, bool skipPublishedInterfaces)` | Publishes a single object as the implementation for multiple interfaces. If `skipPublishedInterfaces` is `false`, throws `ArgumentException` for any already-published interface; if `true`, silently skips already-published interfaces. |
| `bool Exists<T>() where T : class` | Returns `true` if interface type `T` has been published; otherwise `false`. |
| `bool Exists(Type t)` | Returns `true` if the specified interface type has been published; otherwise `false`. |
| `T Get<T>() where T : class` | Returns the published service for interface type `T`. Throws `ArgumentException` if `T` has not been published. |
| `void Clear<T>() where T : class` | Unpublishes the service for interface type `T` if it exists. Fires an unpublish event. |
| `void Clear(IEnumerable