Skip to content

Changes to IResolveContext interface #207

Open
@ENikS

Description

@ENikS

IResolveContext interface

During resolution, the IResolveContext interface provides a way for the build pipeline to resolve dependencies.

Usage

It is used in every resolver pipeline as this:

public delegate object? ResolveDelegate<TContext>(ref TContext context)
        where TContext : IResolveContext;
{
    // Resolution code ...
}

It is defined as follows:

    public interface IResolveContext : IPolicyList
    {
        IUnityContainer Container { get; }

        Type Type { get; }

        string? Name { get; }

        object? Resolve(Type type, string? name);
    }

The interface exposes a type and the name of the currently resolved instance and provides a method to get other dependencies by calling Resolve(otherType, otherName). The method automatically checks if any dependency overrides are provided an returns matching overrides as necessary.

Problem

The interface declaration presents two problems:

  • It is derived from IPolicyList
  • It exposes IUnityContainer

IPolicyList interface

IPolicyList interface allows setting and retrieving container internal policies and makes it vulnerable. In other words, a simple resolver could redefine the container's behavior without any limit.

IUnityContainer member

The container's instance exposed to the resolver allows bypassing of resolution pipeline code and creates situations with a nondeterministic state.

Solution

The new interface should remove both: IPolicyList and IUnityContainer interfaces and will be defined as follows:

    public interface IResolveContext
    {
        Type Type { get; }

        string? Name { get; }

        object? Resolve(Type type, string? name);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions