Ejemplo n.º 1
0
        public void Returns_different_provider_for_configured_services_differing_by_instance()
        {
            var config1 = CreateOptions(b =>
            {
                b.ServiceCollection.AddSingleton <IFakeServiceA, FakeService1>();
                b.ServiceCollection.AddSingleton <FakeService3>();
                b.ServiceCollection.AddInstance(new FakeService4());
            });

            var config2 = CreateOptions(b =>
            {
                b.ServiceCollection.AddSingleton <IFakeServiceA, FakeService1>();
                b.ServiceCollection.AddSingleton <FakeService3>();
                b.ServiceCollection.AddInstance(new FakeService4());
            });

            var cache = new ServiceProviderCache();

            Assert.NotSame(cache.GetOrAdd(config1), cache.GetOrAdd(config2));
        }
        public void Returns_different_provider_for_configured_services_differing_by_instance()
        {
            var config1 = CreateOptions(b =>
                {
                    b.ServiceCollection.AddSingleton<IFakeServiceA, FakeService1>();
                    b.ServiceCollection.AddSingleton<FakeService3>();
                    b.ServiceCollection.AddInstance(new FakeService4());
                });

            var config2 = CreateOptions(b =>
                {
                    b.ServiceCollection.AddSingleton<IFakeServiceA, FakeService1>();
                    b.ServiceCollection.AddSingleton<FakeService3>();
                    b.ServiceCollection.AddInstance(new FakeService4());
                });

            var cache = new ServiceProviderCache();

            Assert.NotSame(cache.GetOrAdd(config1), cache.GetOrAdd(config2));
        }
Ejemplo n.º 3
0
        public void Returns_same_provider_for_same_set_of_configured_services()
        {
            var serviceInstance = new FakeService4();

            var config1 = CreateOptions(b =>
            {
                b.ServiceCollection.AddSingleton <IFakeServiceA, FakeService1>();
                b.ServiceCollection.AddSingleton <FakeService3>();
                b.ServiceCollection.AddInstance(serviceInstance);
            });

            var config2 = CreateOptions(b =>
            {
                b.ServiceCollection.AddSingleton <IFakeServiceA, FakeService1>();
                b.ServiceCollection.AddSingleton <FakeService3>();
                b.ServiceCollection.AddInstance(serviceInstance);
            });

            var cache = new ServiceProviderCache();

            Assert.Same(cache.GetOrAdd(config1), cache.GetOrAdd(config2));
        }
        public void Returns_same_provider_for_same_set_of_configured_services()
        {
            var serviceInstance = new FakeService4();

            var config1 = CreateOptions(b =>
                {
                    b.ServiceCollection.AddSingleton<IFakeServiceA, FakeService1>();
                    b.ServiceCollection.AddSingleton<FakeService3>();
                    b.ServiceCollection.AddInstance(serviceInstance);
                });

            var config2 = CreateOptions(b =>
                {
                    b.ServiceCollection.AddSingleton<IFakeServiceA, FakeService1>();
                    b.ServiceCollection.AddSingleton<FakeService3>();
                    b.ServiceCollection.AddInstance(serviceInstance);
                });

            var cache = new ServiceProviderCache();

            Assert.Same(cache.GetOrAdd(config1), cache.GetOrAdd(config2));
        }