ContainerScopeRegisterForDisposal Method (Object)

Simple Injector
Adds the disposable to the list of items that will get disposed when the container gets disposed.

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

public void RegisterForDisposal(
	Object disposable
)

Parameters

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

ExceptionCondition
ArgumentNullExceptionThrown when one of the arguments is a null reference.
ArgumentExceptionThrown when one of the arguments is not a disposable type.
ObjectDisposedExceptionThrown when the container 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