ILifetimeContainer interface
Lifetime container holds references to disposable instances the container created or registered. It is responsible for properly disposing of these objects once the container goes out of scope. The ILifetimeContainer interface is a facade allowing adding and removing of instances to the container. The interface is declared as the following:
public interface ILifetimeContainer : IEnumerable<object>, IDisposable
{
IUnityContainer Container { get; }
int Count { get; }
void Add(object item);
void Remove(object item);
bool Contains(object item);
}
Problem
ILifetimeContainer operates on objects instead of IDisposable. It is possible to add an object that is not IDisposable
- The interface is derived from
IDisposable. It allowed disposing of the entire container scope from within the user's code.
- This interface references the owner container and could be used to resolve dependencies inside the
GetValue/SetValue handlers.
Solution
To remedy existing vulnerabilities, the interface will be changed as follows:
public interface ILifetimeContainer : IEnumerable<IDisposable>
{
int Count { get; }
void Add(IDisposable item);
void Remove(IDisposable item);
bool Contains(IDisposable item);
}
ILifetimeContainerinterfaceLifetime container holds references to disposable instances the container created or registered. It is responsible for properly disposing of these objects once the container goes out of scope. The
ILifetimeContainerinterface is a facade allowing adding and removing of instances to the container. The interface is declared as the following:Problem
ILifetimeContaineroperates on objects instead ofIDisposable.It is possible to add an object that is notIDisposableIDisposable. It allowed disposing of the entire container scope from within the user's code.GetValue/SetValuehandlers.Solution
To remedy existing vulnerabilities, the interface will be changed as follows: