Exemplo n.º 1
0
        public void ShouldCallCacheOnCachedServiceType()
        {
            var map                  = new DependencyMap();
            var dependency           = new Dependency(typeof(IFoo));
            var implementation       = new TransientType(typeof(Foo), map, new ConstructorResolver());
            var cachedImplementation = new CachedInstantiation(implementation);

            map.AddSingletonService <ICache, MockCache>();
            map.AddService(dependency, cachedImplementation);

            // Compile the container
            var container = map.CreateContainer();

            // Grab the service instance
            var firstResult  = container.GetInstance <IFoo>();
            var secondResult = container.GetInstance <IFoo>();

            Assert.IsNotNull(firstResult);
            Assert.AreSame(firstResult, secondResult);
        }
Exemplo n.º 2
0
        public void ShouldCallCacheOnCachedServiceType()
        {
            var map = new DependencyMap();
            var dependency = new Dependency(typeof(IFoo));
            var implementation = new TransientType(typeof(Foo), map, new ConstructorResolver());
            var cachedImplementation = new CachedInstantiation(implementation);

            map.AddSingletonService<ICache, MockCache>();
            map.AddService(dependency, cachedImplementation);

            // Compile the container
            var container = map.CreateContainer();

            // Grab the service instance
            var firstResult = container.GetInstance<IFoo>();
            var secondResult = container.GetInstance<IFoo>();

            Assert.IsNotNull(firstResult);
            Assert.AreSame(firstResult, secondResult);
        }