This is a kernel with a parent kernel. Any binding that can not be resolved by this kernel is forwarded to the parent.
Inheritance: Ninject.StandardKernel, IChildKernel
Example #1
0
 private static ChildKernel CreateAuthKernel(IResolutionRoot parent)
 {
     var kernel = new ChildKernel(parent, new ServerModule(), new AuthServerModule());
     kernel.Rebind<IPacketCodeTable>().To<AuthPacketCodeTableV75>().InSingletonScope();
     kernel.Rebind<IAuthenticator>().To<StubAuthenticator>().InSingletonScope();
     kernel.Rebind<IAccountProvider>().To<StubAccountProvider>().InSingletonScope();
     return kernel;
 }
Example #2
0
        public void ChildKernel_IFooBoundInChildKernel_ParentKernelCannotResolveIFoo()
        {
            // Assemble
            var parentKernel = new StandardKernel();

            var childKernel = new ChildKernel(parentKernel);
            childKernel.Bind<IFoo>().To<Foo>();

            // Act
            Assert.Throws<ActivationException>(() => parentKernel.Get<IFoo>());
        }
Example #3
0
        public SimpleBootstrapper(IResolutionRoot resolutionRoot, ILogger logger)
            : base(resolutionRoot, logger)
        {
            var nexus = new ChildKernel(this.ResolutionRoot, new NexusServerModule());

            this.account = new ChildKernel(nexus, new AccountServerModule());
            this.auth = CreateAuthKernel(nexus);
            this.world = new ChildKernel(nexus, new WorldServerModule());
            this.channel = new ChildKernel(this.world, new ServerModule(), new ChannelServerModule());

            // HACK :(
            nexus.Bind<IAccountService>().ToMethod(ctx => this.account.Get<IAccountService>());
        }
Example #4
0
        public void ChildKernel_IFooBoundInParentAndChildKernel_ParentCanResolveIFoo()
        {
            // Assemble
            var parentKernel = new StandardKernel();
            parentKernel.Bind<IFoo>().To<Foo1>();

            var childKernel = new ChildKernel(parentKernel);
            childKernel.Bind<IFoo>().To<Foo2>();

            // Act
            var foo = parentKernel.Get<IFoo>();

            // Act
            Assert.IsInstanceOf<Foo1>(foo);
        }
 private NinjectServiceRegistry(NinjectServiceRegistry parent)
 {
     _parent = parent;
       if (_parent != null)
       {
           var childKernel = new ChildKernel(_parent._kernel);
           _kernel = childKernel;
           _kernel.Bind<IChildKernel>().ToConstant(childKernel);
       }
       else
       {
           _kernel = new StandardKernel();
       }
       _locator = new NinjectServiceLocator(_kernel, _parent != null ? _parent._locator : null);
     _kernel.Bind<IServiceRegistry>().ToConstant(this);
     _kernel.Bind<IServiceLocator>().ToConstant(_locator);
 }
Example #6
0
        public void ChildKernel_SameInterfaceBoundInTwoChildKernels_EachKernelResolvesInstanceCorrectly()
        {
            // Assemble
            var parentKernel = new StandardKernel();
            parentKernel.Bind<IBar>().To<Bar>();

            var barNoneKernel = new ChildKernel(parentKernel);
            barNoneKernel.Bind<IFoo>().To<Foo>();

            var allTheBarsKernel = new ChildKernel(parentKernel);
            allTheBarsKernel.Bind<IFoo>().To<FooDependingOnBar>();

            // Act
            var barNone = barNoneKernel.Get<IFoo>();
            var bars = allTheBarsKernel.Get<IFoo>();

            // Assert

            Assert.IsInstanceOf<Foo>(barNone);
            Assert.IsInstanceOf<FooDependingOnBar>(bars);
        }
Example #7
0
        public IEngine Create(IReadOnlyCollection<EntityData> snapshot, IReadOnlyCollection<EntityTemplate> templates)
        {
            _logger.Info("Creating new RuntimeEngine instance");

            // Create a child kernel for this new instance.
            var k = new ChildKernel(_kernel, new NinjectSettings()
            {
                InjectNonPublic = true
            });

            k.Load(_kernel.GetAll<IEngineModule>());
            k.Bind<IEntityTemplateProvider>().ToConstant(new RuntimeEntityTemplateProvider(templates));

            IList<EngineEntity> existingEntities = new List<EngineEntity>();
            foreach (var entity in snapshot)
            {
                existingEntities.Add(new EngineEntity(entity.Id, entity.Components, k.Get<IEventDispatcher>()));
            }

            k.Get<IEntityService>(new ConstructorArgument("entities", existingEntities));

            return k.Get<IEngine>();
        }
Example #8
0
        public IContext CreateDeviceInContext(Settings.IProvider settingsProvider, Messaging.Client.IEndpoint clientEndpoint)
        {
            ChildKernel kernel = new ChildKernel(_kernel);

            kernel.Bind<Command.Response.IBuilder>().To<Command.Response.Builder.VersionResponse>().InSingletonScope();
            kernel.Bind<Command.Response.IBuilder>().To<Command.Response.Builder.RostaResponse>().InSingletonScope();
            kernel.Bind<Command.Response.IBuilder>().To<Command.Response.Builder.DeviceResponse>().InSingletonScope();
            kernel.Bind<Command.Response.IBuilder>().To<Command.Response.Builder.UdpResponse>().InSingletonScope();
            kernel.Bind<Command.Response.IBuilder>().To<Command.Response.Builder.SaveResponse>().InSingletonScope();
            kernel.Bind<Command.Response.IParser>().To<Command.Response.Parser>().InSingletonScope();
            kernel.Bind<Command.Endpoint.IFactory>().To<Command.Endpoint.Factory>().InSingletonScope();
            
            kernel.Bind<Packet.IParser>().To<Packet.Parser>().InSingletonScope();
            kernel.Bind<Packet.Endpoint.IFactory>().To<Packet.Endpoint.Factory>().InSingletonScope();

            kernel.Bind<Event.IMediator>().To<Event.Mediator>().InSingletonScope();
            kernel.Bind<State.Event.IFactory>().To<State.Event.Factory>().InSingletonScope();
            kernel.Bind<State.Context.IFactory>().To<State.Context.Factory>().InSingletonScope();
            
            kernel.Bind<State.ITransition>().To<State.Transition>().InSingletonScope();
            kernel.Bind<State.IFactory>().To<State.Factory>().InSingletonScope();
            kernel.Bind<State.IMachine>().To<State.Machine>().InSingletonScope();

            kernel.Bind<Entity.IFactory>().To<Entity.Factory>().InSingletonScope();

            kernel.Bind<Entity.Observable.IFactory>().To<Entity.Observable.CurrentElectricityConsumptionFactory>().InSingletonScope();
            kernel.Bind<Entity.Observable.IAbstractFactory>().To<Entity.Observable.AbstractFactory>().InSingletonScope();

            kernel.Bind<IBridge>().To<Bridge>().InSingletonScope();
            kernel.Bind<IInstance>().To<Instance>().InSingletonScope();
            kernel.Bind<IContext>().To<Context>().InSingletonScope();

            kernel.Bind<Settings.IProvider>().ToConstant(settingsProvider);
            kernel.Bind<Messaging.Client.IEndpoint>().ToConstant(clientEndpoint);

            return kernel.Get<IContext>();
        }
 public NInjectChildContainerAdapter(ChildKernel childKernel)
 {
     this.childKernel = childKernel;
 }