public void Register_singleton_should_be_supported()
 {
     ForAllBuilders((builder) =>
     {
         var singleton = new SingletonComponent();
         builder.RegisterSingleton(typeof(ISingletonComponent), singleton);
         builder.RegisterSingleton(typeof(SingletonComponent), singleton);
         Assert.AreEqual(builder.Build(typeof(SingletonComponent)), singleton);
         Assert.AreEqual(builder.Build(typeof(ISingletonComponent)), singleton);
     });
 }
        public void Should_not_dispose_singletons_when_container_goes_out_of_scope()
        {
            ForAllBuilders(builder =>
            {
                var singletonInMainContainer = new SingletonComponent();

                builder.RegisterSingleton(typeof(ISingletonComponent), singletonInMainContainer);
                builder.Configure(typeof(ComponentThatDependsOfSingleton), DependencyLifecycle.InstancePerUnitOfWork);

                using (var nestedContainer = builder.BuildChildContainer())
                    nestedContainer.Build(typeof(ComponentThatDependsOfSingleton));

                Assert.False(SingletonComponent.DisposeCalled);
            },
                           typeof(SpringObjectBuilder));
        }
        public void Should_not_dispose_singletons_when_container_goes_out_of_scope()
        {
            ForAllBuilders(builder =>
            {
                var singletonInMainContainer = new SingletonComponent();

                builder.RegisterSingleton(typeof(ISingletonComponent), singletonInMainContainer);
                builder.Configure(typeof(ComponentThatDependsOfSingleton), DependencyLifecycle.InstancePerUnitOfWork);

                using (var nestedContainer = builder.BuildChildContainer())
                {
                    nestedContainer.Build(typeof(ComponentThatDependsOfSingleton));
                }

                Assert.False(SingletonComponent.DisposeCalled);
            },
            typeof(SpringObjectBuilder));
        }
        public void Should_be_able_to_reregister_a_component_locally()
        {
            ForAllBuilders(builder =>
            {
                var singletonInMainContainer = new SingletonComponent();
                builder.RegisterSingleton(typeof(ISingletonComponent), singletonInMainContainer);

                var nestedContainer = builder.BuildChildContainer();

                Assert.IsInstanceOf<SingletonComponent>(builder.Build(typeof(ISingletonComponent)));

                var singletonInNestedContainer = new AnotherSingletonComponent();

                nestedContainer.RegisterSingleton(typeof(ISingletonComponent), singletonInNestedContainer);

                Assert.IsInstanceOf<SingletonComponent>(builder.Build(typeof(ISingletonComponent)));
                Assert.IsInstanceOf<AnotherSingletonComponent>(nestedContainer.Build(typeof(ISingletonComponent)));

            },
            typeof(SpringObjectBuilder),
            typeof(WindsorObjectBuilder),
            typeof(UnityObjectBuilder),
            typeof(NinjectObjectBuilder));
        }
 public void Register_singleton_should_be_supported()
 {
     VerifyForAllBuilders((builder) =>
     {
         var singleton = new SingletonComponent();
         builder.RegisterSingleton(typeof(ISingletonComponent), singleton);
         builder.RegisterSingleton(typeof(SingletonComponent), singleton);
         Assert.AreEqual(builder.Build(typeof(SingletonComponent)), singleton);
         Assert.AreEqual(builder.Build(typeof(ISingletonComponent)), singleton);
     }, typeof(UnityObjectBuilder));
 }