Exemple #1
0
        public void Returns_different_provider_for_configured_services_differing_by_lifetime()
        {
            var serviceInstance = new FakeService4();

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

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

            var cache = new ServiceProviderCache();

            Assert.NotSame(cache.GetOrAdd(config1), cache.GetOrAdd(config2));
        }
Exemple #2
0
        public void Returns_same_provider_for_same_set_of_configured_services()
        {
            var serviceInstance = new FakeService4();

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

            var config2 = CreateOptions(b =>
            {
                b.GetService().AddSingleton <IFakeServiceA, FakeService1>();
                b.GetService().AddSingleton <FakeService3>();
                b.GetService().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.GetService().AddSingleton<IFakeServiceA, FakeService1>();
                    b.GetService().AddSingleton<FakeService3>();
                    b.GetService().AddInstance(serviceInstance);
                });

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

            var cache = new ServiceProviderCache();

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

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

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

            var cache = new ServiceProviderCache();

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

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

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

            var cache = new ServiceProviderCache();

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