Esempio n. 1
0
        public override TImpl ResolveTypedInstance()
        {
            var injector = InjectorCache.GetOrCreateInjector(typeof(TImpl));
            var instance = injector.CreateInstance <TImpl>(diContainer);

            return(instance);
        }
Esempio n. 2
0
        private void AddInjectorDependencies(InjectionKey injected)
        {
            var injector = InjectorCache.GetOrCreateInjector(injected.InjectedResourceType);

            foreach (var dependsOn in injector.DependsOn)
            {
                AddDependency(injected, dependsOn, false);
            }
        }
Esempio n. 3
0
        public void TestInjectorCache()
        {
            InjectorCache.ClearCache();

            //Should reuse the first instance of an injector
            var instance = InjectorCache.GetOrCreateInjector(typeof(IInterface));

            Assert.IsNotNull(instance, "Injector instance should not be null");
            Assert.AreEqual(1, InjectorCache.CachedInjectorCount);
            var secondInstance = InjectorCache.GetOrCreateInjector(typeof(IInterface));

            Assert.AreEqual(1, InjectorCache.CachedInjectorCount);
            Assert.IsTrue(ReferenceEquals(instance, secondInstance), "Should reuse injector instance!");

            //Clear should reset to zero
            InjectorCache.ClearCache();
            Assert.AreEqual(0, InjectorCache.CachedInjectorCount);
        }