{"id":24399637,"url":"https://github.com/open-net-libraries/open.disposable","last_synced_at":"2025-09-23T10:48:38.571Z","repository":{"id":60773153,"uuid":"104616020","full_name":"Open-NET-Libraries/Open.Disposable","owner":"Open-NET-Libraries","description":"Provides a set of useful classes when implementing a disposable.","archived":false,"fork":false,"pushed_at":"2024-11-15T15:04:50.000Z","size":126,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-23T10:48:36.942Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Open-NET-Libraries.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-24T03:30:50.000Z","updated_at":"2024-11-15T15:04:53.000Z","dependencies_parsed_at":"2025-04-11T18:53:41.893Z","dependency_job_id":"b700248f-b1b1-43c4-bb0e-476890376691","html_url":"https://github.com/Open-NET-Libraries/Open.Disposable","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Open-NET-Libraries/Open.Disposable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Open-NET-Libraries%2FOpen.Disposable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Open-NET-Libraries%2FOpen.Disposable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Open-NET-Libraries%2FOpen.Disposable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Open-NET-Libraries%2FOpen.Disposable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Open-NET-Libraries","download_url":"https://codeload.github.com/Open-NET-Libraries/Open.Disposable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Open-NET-Libraries%2FOpen.Disposable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276562597,"owners_count":25664430,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-19T23:50:43.953Z","updated_at":"2025-09-23T10:48:38.544Z","avatar_url":"https://github.com/Open-NET-Libraries.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Open.Disposable\n\nProvides a set of useful classes when implementing a disposable.\n\n[![NuGet](https://img.shields.io/nuget/v/Open.Disposable.svg)](https://www.nuget.org/packages/Open.Disposable/)\n\n## Core principles\n\n* For most use cases, disposal should only occur once and be final.\n* Implementing `IDisposable` in combination with `IAsyncDisposable` is not typical and should be avoided.  The consumer should understand the difference.\n* `.Dispose()` and `.DisposeAsync()` should be thread-safe and calling either multiple times should not block or throw. (Typically done through an interlock method.)\n\n### Avoid anti-patterns\n\n#### Memory\n\nIt can be all too easy to allocate more memory by constructing more classes or starting new tasks in order to complete disposal.  This is counter to the intention of cleaning up a class and reducing the amount of work the garbage collector has to do.\n\n#### Plan for the worst, but code for the best\n\nThread safety is important and in many cases should be assured.  But when the 99% case is the local use of a class, over-engineering can simply create unnecessary overhead and contention.\n\n#### Let the GC do its job\n\nAggressively attempting to help out the garbage collector can be a serious anti-pattern as you are simply slowing down your own application in order to avoid GC operations which might actually be helping your performance in total by deferring cleanup.\n\n## Classes\n\n### `DisposableBase`\n\nSimply implement `void OnDispose()` in order to manage disposal.\n\n\u003e Note: `DisposableBase` exposes a `BeforeDispose` event which will be triggered once just before disposing commences.  This allows for others to react to this disposal event.  The `DisposableBase` is still considered 'live' until after the `BeforeDispose` event cycle has completed.\n\n### `AsyncDisposableBase`\n\nSimply implement `ValueTask OnDisposeAsync()` in order to manage disposal.\n\n### `DisposeHandler` \u0026 `AsyncDisposeHandler`\n\nA simple set of classes for triggering an action (once) when disposed.  Can also contain a value (T) which is cleared on dispose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-net-libraries%2Fopen.disposable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-net-libraries%2Fopen.disposable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-net-libraries%2Fopen.disposable/lists"}