Skip to content

ILifetimeContainer interface changes #206

Description

@ENikS

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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement 🔨Improvement of existing features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions