Design patterns =============== **Energy.Base.Pattern** is a static repository of common design-pattern implementations. GlobalObject --------------- Provides a process-wide singleton instance. The object is created lazily on first access. ```csharp public class MyService { public string Name { get; set; } } MyService service = Energy.Base.Pattern.GlobalObject.Global; service.Name = "Default"; // Later in the same process MyService same = Energy.Base.Pattern.GlobalObject.Global; Console.WriteLine(same.Name); // "Default" ``` GlobalDestroy ---------------- Like `GlobalObject`, but also provides a `Destroy()` method that disposes the current instance (if it implements `IDisposable`) so the next access creates a new one. ```csharp Energy.Base.Pattern.GlobalDestroy.Destroy(); ``` DefaultProperty ------------------ Provides a lazy default instance. ```csharp Energy.Base.Pattern.DefaultProperty.Default.Name = "Default"; ``` Singleton ------------ Provides a singleton instance through an instance wrapper. ```csharp Energy.Base.Pattern.Singleton singleton = new Energy.Base.Pattern.Singleton(); Console.WriteLine(singleton.Instance.Name); ``` Summary ------- | Pattern | Description | |---------|-------------| | `GlobalObject` | Lazy global singleton. | | `GlobalDestroy` | Global singleton with explicit disposal. | | `DefaultProperty` | Lazy default instance. | | `Singleton` | Singleton wrapper. |