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

indirect depencies are not resolved by the child kernel. #9

Open
Steinblock opened this issue Nov 26, 2015 · 2 comments
Open

indirect depencies are not resolved by the child kernel. #9

Steinblock opened this issue Nov 26, 2015 · 2 comments

Comments

@Steinblock
Copy link

First of all, I am not sure if this is an issue or by design If it is by design, I would appreciate a hint how to refactor my code.

Consider the following setup.

        public interface IService
        {
            string Name { get; }
        }
        public interface IServiceProvider
        {
            IService GetService();
        }
        public class Service : IService
        {
            public string Name { get; set; }
        }
        public class ServiceProvider : IServiceProvider
        {
            private IService service;
            public ServiceProvider(IService service)
            {
                this.service = service;
            }
            public IService GetService()
            {
                return service;
            }
        }

My binding looks like this:

var container = new StandardKernel();
container.Bind<IService>().ToMethod(ctx => new Service { Name = "Parent" });
container.Bind<IServiceProvider>().To<ServiceProvider>();
var provider1 = container.Get<IServiceProvider>();
var service1a = container.Get<IService>(); // = Parent
var service1b = provider1.GetService(); // = Parent

var child = new ChildKernel(container);
child.Bind<IService>().ToMethod(ctx => new Service { Name = "Child" });
var provider2 = child.Get<IServiceProvider>();
var service2a = child.Get<IService>(); // = Child
var service2b = provider2.GetService(); // = Parent

In the child kernel I want to bind IService to my custom implementation ("Child") which works but I also want IServiceProvider to use the custom implementation without rebinding (In fact I can't since in my real world app IServiceProvider is out of my scope).

I found two different entries for this:
a) issue #7 "Child kernel bindings not being used to resolve dependencies" which seems to be the same problem but is from 2013
b) the readme which claims Since version 3.0, implicit bindngs are resolved on the child kernel and not the parent kernel anymore.

b) sounds as this should be possible since 3.0. I am using Ninject 3.2 and Ninject.Extensions.ChildKernel 3.2` .

@johnknoop
Copy link

Is this project still maintained?

@drieseng
Copy link
Member

The Ninject project is still very much alive, although I would very much welcome other contributors.
I hope to find time soon to revive the ChildKernel extension, but any help is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants