Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to IResolveContext interface #207

Open
ENikS opened this issue Mar 14, 2023 · 0 comments
Open

Changes to IResolveContext interface #207

ENikS opened this issue Mar 14, 2023 · 0 comments
Labels
Breaking change ❕ This change breaks public API Enhancement 🔨 Improvement of existing features

Comments

@ENikS
Copy link
Contributor

ENikS commented Mar 14, 2023

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);
    }
@ENikS ENikS added Enhancement 🔨 Improvement of existing features Breaking change ❕ This change breaks public API labels Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change ❕ This change breaks public API Enhancement 🔨 Improvement of existing features
Projects
None yet
Development

No branches or pull requests

1 participant