public void ShouldNotConsiderNonPublicConstructors() { DefaultPicoContainer pico = new DefaultPicoContainer(); pico.RegisterComponentImplementation(typeof(Component201)); pico.RegisterComponentInstance(2); pico.RegisterComponentInstance(true); pico.RegisterComponentInstance("Hello"); Assert.IsNotNull(pico.GetComponentInstance(typeof(Component201))); }
public IMutablePicoContainer Compose() { DefaultPicoContainer p = new DefaultPicoContainer(parent); p.RegisterComponentInstance("hello", "C#"); return p; }
public DefaultNanoContainer(StreamReader composition, String builderClass) { DefaultReflectionContainerAdapter defaultReflectionContainerAdapter; DefaultPicoContainer dpc = new DefaultPicoContainer(); dpc.RegisterComponentInstance(composition); defaultReflectionContainerAdapter = new DefaultReflectionContainerAdapter(dpc); IComponentAdapter componentAdapter = defaultReflectionContainerAdapter.RegisterComponentImplementation(builderClass); containerBuilder = (ScriptedContainerBuilder) componentAdapter.GetComponentInstance(dpc); }
public void BuildContainerFromMoreThanOneAssembly() { StringCollection assemblies = new StringCollection(); assemblies.Add("../../../TestCompWithAttributes/bin/Debug/TestCompWithAttributes.dll"); assemblies.Add("../../../NotStartable/bin/Debug/NotStartable.dll"); IMutablePicoContainer parent = new DefaultPicoContainer(); parent.RegisterComponentInstance(new StringBuilder("This is needed for type NotStartable")); ContainerBuilderFacade cbf = new AttributeBasedContainerBuilderFacade(); IMutablePicoContainer picoContainer = cbf.Build(parent, assemblies); Assert.IsNotNull(picoContainer.GetComponentInstance("testcomp3-key")); Assert.IsNotNull(picoContainer.GetComponentInstance("notstartable")); }
public void ComponentInstancesFromParentsAreNotDirectlyAccessible() { IMutablePicoContainer a = new DefaultPicoContainer(); IMutablePicoContainer b = new DefaultPicoContainer(a); IMutablePicoContainer c = new DefaultPicoContainer(b); object ao = new object(); object bo = new object(); object co = new object(); a.RegisterComponentInstance("a", ao); b.RegisterComponentInstance("b", bo); c.RegisterComponentInstance("c", co); Assert.AreEqual(1, a.ComponentInstances.Count); Assert.AreEqual(1, b.ComponentInstances.Count); Assert.AreEqual(1, c.ComponentInstances.Count); }
public void ComponentInstancesFromParentsAreNotDirectlyAccessible() { IMutablePicoContainer a = new DefaultPicoContainer(); IMutablePicoContainer b = new DefaultPicoContainer(a); IMutablePicoContainer c = new DefaultPicoContainer(b); object ao = new object(); object bo = new object(); object co = new object(); a.RegisterComponentInstance("a", ao); b.RegisterComponentInstance("b", bo); c.RegisterComponentInstance("c", co); Assert.AreEqual(1, a.ComponentInstances.Count); Assert.AreEqual(1, b.ComponentInstances.Count); Assert.AreEqual(1, c.ComponentInstances.Count); }
public void CollectionsAreGeneratedOnTheFly() { IMutablePicoContainer mpc = new DefaultPicoContainer(); mpc.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof(Bowl))); mpc.RegisterComponentImplementation(typeof(Cod)); Bowl bowl = (Bowl)mpc.GetComponentInstance(typeof(Bowl)); Assert.AreEqual(1, bowl.cods.Length); mpc.RegisterComponentInstance("Nemo", new Cod()); bowl = (Bowl)mpc.GetComponentInstance(typeof(Bowl)); Assert.AreEqual(2, bowl.cods.Length); try { Assert.AreSame(bowl.cods[0], bowl.cods[1]); Assert.Fail("cods should not be the same"); } catch (AssertionException) { } }
public void ShouldNotConsiderNonPublicConstructors() { DefaultPicoContainer pico = new DefaultPicoContainer(); pico.RegisterComponentImplementation(typeof (Component201)); pico.RegisterComponentInstance(2); pico.RegisterComponentInstance(true); pico.RegisterComponentInstance("Hello"); Assert.IsNotNull(pico.GetComponentInstance(typeof (Component201))); }
public void CollectionsAreGeneratedOnTheFly() { IMutablePicoContainer mpc = new DefaultPicoContainer(); mpc.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof (Bowl), typeof (Bowl))); mpc.RegisterComponentImplementation(typeof (Cod)); Bowl bowl = (Bowl) mpc.GetComponentInstance(typeof (Bowl)); Assert.AreEqual(1, bowl.cods.Length); mpc.RegisterComponentInstance("Nemo", new Cod()); bowl = (Bowl) mpc.GetComponentInstance(typeof (Bowl)); Assert.AreEqual(2, bowl.cods.Length); try { Assert.AreSame(bowl.cods[0], bowl.cods[1]); Assert.Fail("cods should not be the same"); } catch (AssertionException) { } }