Skip to content

ExcludeTypeFromAutoRegistration dosn't do anything for ChildContainers #299

@Warstone

Description

@Warstone
public class B
{
    public B(A a)
    {
        A = a;
    }

    public A A;
}
public class A
{
    public int Value;
}

public static class Program
{
    public static void Main()
    {
        var container = new DependencyInjectionContainer();
        container.Configure(c =>
        {
            // c.ExcludeTypeFromAutoRegistration(typeof(A)); // Uncomment this line for correct answer
        });

        var origA = new A() { Value = 5 };
        var subContainer = container.CreateChildScope();
        subContainer.Configure(c =>
        {
            c.ExcludeTypeFromAutoRegistration(typeof(A)); // This line is useless
        });

        B obj = subContainer.Locate<B>(new {
            a = origA
        });
        
        Console.Write($"obj A val = {obj.A.Value}"); // This will write "obj A val = 0", expected result: "obj A val = 5"
    }
}

Here is the code illustrating example. If I exclude AutoRegistration in child container (I want to override parent behaviour) it won't work. I need to exclude it in parent container.

So Excluding in child containers dosn't do anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions