Skip to content

ctx.RootType should be the type which Resolve calls #154

Description

@scott-xu

Describe the bug
I think the ctx.RootType should be the type which Resolve calls. However, it is lightweight root.

To Reproduce

namespace PureDIRootTypeTest
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Pure.DI;
    using Shouldly;

    internal partial class Program
    {
        private static void Setup() => DI.Setup()
            .Bind().To(ctx => new Logger(ctx.RootType))
            .Root<Parent>();

        static void Main(string[] args)
        {
            var parent = new Program().Resolve<Parent>();
            parent.Child.Logger.Type.ShouldBeOfType<Parent>(); // It is LightweightRoot264d
        }
    }

    public class Parent
    {
        public Parent(Child child)
        {
            Child = child;
        }
        public Child Child { get; }
    }


    public class Child
    {
        public Child(Logger logger)
        {
            Logger = logger;
        }
        public Logger Logger { get; }
    }

    public class Logger
    {
        public Logger(Type type)
        {
            Type = type;
        }

        public Type Type { get; }
    }
}

Expected behavior
type of Parent

Activity

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions