Esempio n. 1
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>());
        }
Esempio n. 2
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>());
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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>();
        }
Esempio n. 6
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>();
        }