public void Registering_the_same_singleton_for_different_interfaces_should_be_supported()
        {
            var serviceCollection = new ServiceCollection();
            var singleton         = new SingletonThatImplementsToInterfaces();

            serviceCollection.AddSingleton(typeof(ISingleton1), singleton);
            serviceCollection.AddSingleton(typeof(ISingleton2), singleton);
            serviceCollection.ConfigureComponent(typeof(ComponentThatDependsOnMultiSingletons), DependencyLifecycle.InstancePerCall);

            var builder    = BuildContainer(serviceCollection);
            var dependency = (ComponentThatDependsOnMultiSingletons)builder.GetService(typeof(ComponentThatDependsOnMultiSingletons));

            Assert.NotNull(dependency.Singleton1);
            Assert.NotNull(dependency.Singleton2);

            Assert.AreEqual(builder.GetService(typeof(ISingleton1)), singleton);
            Assert.AreEqual(builder.GetService(typeof(ISingleton2)), singleton);
        }
        public void Registering_the_same_singleton_for_different_interfaces_should_be_supported()
        {
            ForAllBuilders(builder =>
            {
                var singleton = new SingletonThatImplementsToInterfaces();
                builder.RegisterSingleton(typeof(ISingleton1), singleton);
                builder.RegisterSingleton(typeof(ISingleton2), singleton);

                builder.Configure(typeof(ComponentThatDependsOnMultiSingletons), DependencyLifecycle.InstancePerCall);

                var dependency = (ComponentThatDependsOnMultiSingletons)builder.Build(typeof(ComponentThatDependsOnMultiSingletons));

                Assert.NotNull(dependency.Singleton1);
                Assert.NotNull(dependency.Singleton2);

                Assert.AreEqual(builder.Build(typeof(ISingleton1)), singleton);
                Assert.AreEqual(builder.Build(typeof(ISingleton2)), singleton);
            }, typeof(SpringObjectBuilder));
        }
Ejemplo n.º 3
0
        public void Registering_the_same_singleton_for_different_interfaces_should_be_supported()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                var singleton = new SingletonThatImplementsToInterfaces();
                builder.RegisterInstance <ISingleton1, SingletonThatImplementsToInterfaces>(singleton);
                builder.RegisterInstance <ISingleton2, SingletonThatImplementsToInterfaces>(singleton);

                builder.RegisterType(typeof(ComponentThatDependsOnMultiSingletons), LifeStyle.Transient);

                var dependency = (ComponentThatDependsOnMultiSingletons)builder.Resolve(typeof(ComponentThatDependsOnMultiSingletons));

                Assert.NotNull(dependency.Singleton1);
                Assert.NotNull(dependency.Singleton2);

                Assert.AreEqual(builder.Resolve(typeof(ISingleton1)), singleton);
                Assert.AreEqual(builder.Resolve(typeof(ISingleton2)), singleton);
            }

            //Not supported by,typeof(SpringObjectBuilder));
        }
Ejemplo n.º 4
0
    public void Registering_the_same_singleton_for_different_interfaces_should_only_build_one_result_when_building_all()
    {
        using (var builder = new WindsorObjectBuilder())
        {
            var singleton = new SingletonThatImplementsToInterfaces();
            builder.RegisterSingleton(typeof(ISingleton1), singleton);
            builder.RegisterSingleton(typeof(ISingleton2), singleton);

            builder.Configure(typeof(ComponentThatDependsOnMultiSingletons), DependencyLifecycle.InstancePerCall);

            var dependency = (ComponentThatDependsOnMultiSingletons)builder.Build(typeof(ComponentThatDependsOnMultiSingletons));

            Assert.NotNull(dependency.Singleton1);
            Assert.NotNull(dependency.Singleton2);

            var builtTypes = builder.BuildAll(typeof(ISingleton1));

            Assert.AreEqual(builtTypes.Count(), 1);
        }

        //Not supported by,typeof(SpringObjectBuilder));
    }