public void Base() { IDependencyContainer root = new SimpleDependencyContainer(); IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain(); using (ITypeExecutorService executorService = reflectionService.PrepareTypeExecutors()) { executorService.AddDependencies(root); } root.Resolve <IOutputWriter>(); using (IDependencyProvider s1 = root.Scope("S1")) { s1.Resolve <Counter>(); s1.Resolve <Counter>(); s1.Resolve <Counter>(); Assert.AreEqual(1, Counter.count); } }
private SimpleDependencyContainer(string scopeName, SimpleDependencyContainer parentContainer) { Ensure.NotNullOrEmpty(scopeName, "scopeName"); this.scopeName = scopeName; this.parentContainer = parentContainer; InstanceStorage instances = new InstanceStorage(); if (parentContainer == null) { this.definitions = new DependencyDefinitionCollection(scopeName, instances); } else { this.definitions = new DependencyDefinitionCollection(scopeName, instances, parentContainer.definitions); } this.resolver = new InstanceResolver(definitions, instances); definitions.Add(typeof(IDependencyContainer), DependencyLifetime.NameScope(scopeName), this); definitions.Add(typeof(IDependencyProvider), DependencyLifetime.NameScope(scopeName), this); }