FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bashrc-real/SharedOwner: C# library for managing shared ownership of Disposable reosources · GitHub

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SharedOwner

A library for managing shared resources in C# almost equivalent to shared_ptr

Overview

Despite having the luxury of garbage collector, items that derive from IDisposable needs to be almost treated like a native resource. The owner must take the responsibility of calling Dispose once all the consumers of the resource are no longer using the api. But for some shared reosources their is no implicit owner and hence it becomes difficult to clean up resources in a deterministic manner. This library provides ref counted handle objects managed by a owner class which has the responsibility of calling Dispose once the ref count of the underlying object becomes 0.

Usage

Passing resources to other classes:

var sharedConnection = SharedOwner.SharedHandle<HttpClient>.MakeSharedHandle(() => new HttpClient());
this.m_obj = new Object1(sharedClient);
this.m_obj2 = new Object1(sharedClient);

Getting the object in the client side:

using (var sharedClient = this.m_sharedClient.GetHandle()) // m_sharedClient is the SharedHandle passed
{
     var httpClient = (HttpClient)sharedClient;
     // use httpClient
}
// **Do not use httpClient beyond the using scope of the intermediate handle from GetHandle**

Check BasicTests.cs for sample usage.

About

C# library for managing shared ownership of Disposable reosources

Topics

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages


Back | FazBrowse Home | New Git URL