Skip to content

Resolving on a named binding #261

@InlineAsm

Description

@InlineAsm

When an interface is bound to a class (named) and that class needs the same interface in it's constructor with a different name ninject throws complaining about a cyclic dependency.

This is different from the previous version of ninject which correcly resolved this,

example:

    interface IScreen
    {
        
    }

    class View1 : IScreen
    {
        private readonly IScreen _childView;

        public View1([Named("ChildView")] IScreen childView)
        {
            _childView = childView;
        }
    }

    class ChildView : IScreen
    {
        public ChildView()
        {
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var kernel = new StandardKernel();
            kernel.Bind<IScreen>().To<View1>().Named("MainView");
            kernel.Bind<IScreen>().To<ChildView>().Named("ChildView");

            var instance = kernel.Get<IScreen>("MainView"); // <-- This throws with a cyclic dependency exception
        }
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions