DisposableBucket
Houses IDisposable references across a function that may
create new disposables over time in various scopes, making the
using pattern difficult to manage. For example, the following
snippet makes it hard to declare the new resource in a using statement
and still have access to the resource later in the method.
using (var bucket = new DisposableBucket())
{
...
MyDisposableType resource = null;
if (expression)
{
var resource = GetMyDisposableResource();
bucket.Add(resource)
}
...
// use resource if available
// this use is outside the scope the IDisposable was found in
resource?.MyFunc();
}
public DisposableBucket()