//Parameter module is not used here because we are creating a fake one instead.
        public ChildKernel CreateChildKernelWithModule(IKernel kernel, string module)
        {
            var testModule = new TestValidatorModule();

            var childKernel = new ChildKernel(kernel);

            childKernel.Load(testModule);

            return(childKernel);
        }
        public ChildKernel CreateChildKernelWithModule(IKernel kernel, string module)
        {
            var childKernel = new ChildKernel(kernel);

            log.Debug("Attempting to load module {moduleName} in ChildKernelCreator", module);

            if (!PDFile.Exists(module))
            {
                throw new Exception(string.Format(ValidatorModuleNotFound, module));
            }

            childKernel.Load(module);

            return(childKernel);
        }
示例#3
0
        public void ChildkernelChangedBinding()
        {
            var pluginAKernel = new ChildKernel(this.kernel);

            pluginAKernel.Load(new BarracksModule());

            var pluginBKernel = new ChildKernel(this.kernel);

            pluginBKernel.Bind <IWeapon>().To <Dagger>().WhenInjectedExactlyInto <Samurai>();

            var pluginASamurai = pluginAKernel.Get <Samurai>();
            var pluginBSamurai = pluginBKernel.Get <Samurai>();

            pluginASamurai.Weapon.Should().NotBeSameAs(pluginBSamurai.Weapon);
        }
示例#4
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>());
        }