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>(); }
public void ChildKernel_IFooBoundInParentAndChildKernel_ChildCanResolveIFoo() { // Assemble var parentKernel = new StandardKernel(); parentKernel.Bind<IFoo>().To<Foo1>(); var childKernel = new ChildKernel(parentKernel); childKernel.Bind<IFoo>().To<Foo2>(); // Act var foo = childKernel.Get<IFoo>(); // Act Assert.IsInstanceOf<Foo2>(foo); }
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); }
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>(); }