ScopeRegisterForDisposal Method

Simple Injector
Adds the disposable to the list of items that will get disposed when the scope ends.

Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 4.0.0
Syntax

public void RegisterForDisposal(
	IDisposable disposable
)

Parameters

disposable
Type: SystemIDisposable
The instance that should be disposed when the scope ends.
Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when one of the arguments is a null reference (Nothing in VB).
ObjectDisposedExceptionThrown when the scope has been disposed.
Remarks

Instances that are registered for disposal, will be disposed in opposite order of registration and they are guaranteed to be disposed when Dispose is called (even when exceptions are thrown). This mimics the behavior of the C# and VB
using
statements, where the Dispose method is called inside the
finally
block.
See Also

Reference