public void Given_lookupType_should_be_used_as_service_in_the_registration_when_RegisterSingleton()
        {
            var serviceCollection = new ServiceCollection();
            var expected          = new InheritedFromSomeClass();

            serviceCollection.AddSingleton(typeof(SomeClass), expected);

            var builder = BuildContainer(serviceCollection);

            Assert.AreEqual(expected, builder.GetService(typeof(SomeClass)));

            using (var scope = builder.CreateScope())
            {
                Assert.AreEqual(expected, scope.ServiceProvider.GetService(typeof(SomeClass)));
            }
        }
예제 #2
0
        public void Given_lookupType_should_be_used_as_service_in_the_registration_when_RegisterSingleton()
        {
            ForAllBuilders(builder =>
            {
                var expected = new InheritedFromSomeClass();
                builder.RegisterSingleton(typeof(SomeClass), expected);

                Assert.NotNull(builder.Build(typeof(SomeClass)));
                Assert.AreEqual(expected, builder.Build(typeof(SomeClass)));

                using (var childBuilder = builder.BuildChildContainer())
                {
                    Assert.NotNull(childBuilder.Build(typeof(SomeClass)));
                    Assert.AreEqual(expected, childBuilder.Build(typeof(SomeClass)));
                }
            });
        }