namespace Connected.Middleware; public abstract class MiddlewareComponent : IMiddleware, IDisposable { protected bool IsDisposed { get; private set; } public async Task Initialize() { await OnInitialize(); } protected virtual async Task OnInitialize() { await Task.CompletedTask; } protected virtual void OnDisposing() { } private void Dispose(bool disposing) { if (!IsDisposed) { if (disposing) OnDisposing(); IsDisposed = true; } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } }