protected IMutablePicoContainer CreatePicoContainerWithTouchableAndDependsOnTouchable() { IMutablePicoContainer pico = CreatePicoContainerWithDependsOnTouchableOnly(); pico.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable)); return(pico); }
public void ShouldNotInstantiateCollectionForUngenericCollectionParameters() { IMutablePicoContainer pico = GetDefaultPicoContainer(); pico.RegisterComponentImplementation(typeof(UngenericCollectionBowl)); pico.GetComponentInstance(typeof(UngenericCollectionBowl)); }
public void ShouldFailWhenThereAreNoComponentsToPutInTheArray() { IMutablePicoContainer pico = GetDefaultPicoContainer(); pico.RegisterComponentImplementation(typeof(AnotherGenericCollectionBowl)); pico.GetComponentInstance(typeof(AnotherGenericCollectionBowl)); }
protected override IComponentAdapter prepVER_verificationFails(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof (PersonBean)); return picoContainer.RegisterComponent(new SetterInjectionComponentAdapter( typeof (PurseBean), typeof (MoneyPurse), new IParameter[] {ComponentParameter.DEFAULT})); }
protected override IComponentAdapter prepRES_dependenciesAreResolved(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof(PersonBean)); return (new SetterInjectionComponentAdapter(typeof(PurseBean), new IParameter[] { ComponentParameter.DEFAULT })); }
protected IComponentAdapter prepDEF_isAbleToTakeParameters(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentImplementation(typeof (SimpleTouchable)); return new ConstructorInjectionComponentAdapter(typeof (NamedDependsOnTouchable), typeof (NamedDependsOnTouchable), new IParameter[] { ComponentParameter.DEFAULT, new ConstantParameter("Name") }); }
protected override IComponentAdapter prepDEF_verifyWithoutDependencyWorks(IMutablePicoContainer picoContainer) { return new SetterInjectionComponentAdapter(typeof (PersonBean), typeof (PersonBean), new IParameter[] { new ConstantParameter( "Pico Container") }); }
public void ExternallyInstantiatedObjectsCanBeRegistgeredAndLookUp() { IMutablePicoContainer pico = CreatePicoContainer(); Hashtable map = new Hashtable(); pico.RegisterComponentInstance(typeof(Hashtable), map); Assert.AreSame(map, pico.GetComponentInstance(typeof(Hashtable))); }
protected override IComponentAdapter prepDEF_verifyWithoutDependencyWorks(IMutablePicoContainer picoContainer) { return(new SetterInjectionComponentAdapter(typeof(PersonBean), new IParameter[] { new ConstantParameter( "Pico Container") })); }
public void RegistersSingleInstance() { IMutablePicoContainer pico = CreatePicoContainer(); StringBuilder sb = new StringBuilder(); pico.RegisterComponentInstance(sb); Assert.AreSame(sb, pico.GetComponentInstance(typeof(StringBuilder))); }
protected override IComponentAdapter prepRES_failingInstantiationWithCyclicDependencyException( IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof(PersonBean), typeof(WealthyPerson)); return(picoContainer.RegisterComponent(new SetterInjectionComponentAdapter( typeof(PurseBean), new IParameter[] { ComponentParameter.DEFAULT }))); }
protected override IComponentAdapter prepVER_verificationFails(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof(PersonBean)); return(picoContainer.RegisterComponent(new SetterInjectionComponentAdapter( typeof(PurseBean), typeof(MoneyPurse), new IParameter[] { ComponentParameter.DEFAULT }))); }
prepINS_normalExceptionIsRethrownInsidePicoInvocationTargetInitializationException( IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); return (new SetterInjectionComponentAdapter(typeof(HidingPersion), new IParameter[] { ComponentParameter.DEFAULT })); }
protected override IComponentAdapter prepRES_failingInstantiationWithCyclicDependencyException( IMutablePicoContainer picoContainer) { IComponentAdapter componentAdapter = new ConstructorInjectionComponentAdapter(typeof(C1)); picoContainer.RegisterComponent(componentAdapter); picoContainer.RegisterComponentImplementation(typeof(C2), typeof(C2)); return(componentAdapter); }
private static ITask CreateTool(IMutablePicoContainer picoContext, string fullToolClass) { RegisterType(picoContext, fullToolClass); ITask i = (ITask)picoContext.GetComponentInstance(fullToolClass); Debug.Assert(i != null); return(i); }
public IMutablePicoContainer Build(IMutablePicoContainer parent, IList assemblies) { SimpleReference simpleReference = new SimpleReference(); SimpleReference parentReference = new SimpleReference(); parentReference.Set(parent); containerBuilder.BuildContainer(simpleReference, parentReference, assemblies); return simpleReference.Get() as IMutablePicoContainer; }
public void NonInterfaceImplementaionWithParametersIsAutomaticallyHidden() { IMutablePicoContainer pc = CreateImplementationHidingPicoContainer(); pc.RegisterComponentImplementation(typeof(Hashtable), typeof(Hashtable), new IParameter[0]); IDictionary map = (IDictionary)pc.GetComponentInstance(typeof(Hashtable)); Assert.IsNotNull(map); Assert.IsTrue(map is Hashtable); }
public void UnambiguouSelfDependency() { IMutablePicoContainer pico = CreatePicoContainer(null); pico.RegisterComponentImplementation(typeof(SimpleTouchable)); pico.RegisterComponentImplementation(typeof(DecoratedTouchable)); ITouchable t = (ITouchable)pico.GetComponentInstance(typeof(DecoratedTouchable)); Assert.IsNotNull(t); }
protected IComponentAdapter prepDEF_isAbleToTakeParameters(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof (PersonBean)); return picoContainer.RegisterComponent(new SetterInjectionComponentAdapter( typeof (PurseBean), typeof (MoneyPurse), new IParameter[] { ComponentParameter.DEFAULT, new ConstantParameter(100.0D) })); }
public void ImplementaionIsAutomaticallyHidden() { IMutablePicoContainer pc = CreateImplementationHidingPicoContainer(); pc.RegisterComponentImplementation(typeof(IDictionary), typeof(Hashtable)); IDictionary dictionary = (IDictionary)pc.GetComponentInstance(typeof(IDictionary)); Assert.IsNotNull(dictionary); Assert.IsFalse(dictionary is Hashtable); }
public void AllowsEmptyArraysIfEspeciallySet() { IMutablePicoContainer pico = GetDefaultPicoContainer(); Type type = typeof(AnotherGenericCollectionBowl); pico.RegisterComponentImplementation(type, type, new IParameter[] { ComponentParameter.ARRAY_ALLOW_EMPTY }); AnotherGenericCollectionBowl bowl = (AnotherGenericCollectionBowl)pico.GetComponentInstance(type); Assert.IsNotNull(bowl); Assert.AreEqual(0, bowl.Strings.Length); }
public void ComponentsCanBeRemovedByInstance() { IMutablePicoContainer pico = CreatePicoContainer(); pico.RegisterComponentImplementation(typeof(ArrayList)); IList list = (IList)pico.GetComponentInstanceOfType(typeof(IList)); pico.UnregisterComponentByInstance(list); Assert.AreEqual(0, pico.ComponentAdapters.Count); Assert.AreEqual(0, pico.ComponentInstances.Count); Assert.IsNull(pico.GetComponentInstanceOfType(typeof(IList))); }
public void MultiWithOnlySmallSatisfiedDependencyWorks() { IMutablePicoContainer pico = createPicoContainer(); pico.RegisterComponentImplementation(typeof(Multi)); pico.RegisterComponentImplementation(typeof(One)); pico.RegisterComponentImplementation(typeof(Three)); Multi multi = (Multi)pico.GetComponentInstance(typeof(Multi)); Assert.AreEqual("three one", multi.message); }
public void SameInstanceCanBeUsedAsDifferentType() { IMutablePicoContainer pico = CreatePicoContainer(); pico.RegisterComponentImplementation("wt", typeof(WashableTouchable)); pico.RegisterComponentImplementation("nw", typeof(NeedsWashable)); pico.RegisterComponentImplementation("nt", typeof(NeedsTouchable)); NeedsWashable nw = (NeedsWashable)pico.GetComponentInstance("nw"); NeedsTouchable nt = (NeedsTouchable)pico.GetComponentInstance("nt"); Assert.AreSame(nw.washable, nt.touchable); }
protected IComponentAdapter prepDEF_isAbleToTakeParameters(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentImplementation(typeof(SimpleTouchable)); return (new ConstructorInjectionComponentAdapter(typeof(NamedDependsOnTouchable), typeof(NamedDependsOnTouchable), new IParameter[] { ComponentParameter. DEFAULT, new ConstantParameter ("Name") })); }
protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { _picoContext.Dispose(); _picoContext = null; GC.SuppressFinalize(this); } } _disposed = true; }
public void LazyInstantiation() { IMutablePicoContainer pico = createPicoContainer(); pico.RegisterComponentImplementation(typeof(Kilroy)); pico.RegisterComponentImplementation(typeof(Havana)); Assert.AreSame(pico.GetComponentInstance(typeof(Havana)), pico.GetComponentInstance(typeof(Havana))); Assert.IsNotNull(pico.GetComponentInstance(typeof(Havana))); Assert.AreEqual("Clean wall", ((Havana)pico.GetComponentInstance(typeof(Havana))).paint); Assert.IsNotNull(pico.GetComponentInstance(typeof(Kilroy))); Assert.AreEqual("Kilroy was here", ((Havana)pico.GetComponentInstance(typeof(Havana))).paint); }
protected IComponentAdapter prepDEF_isAbleToTakeParameters(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof(PersonBean)); return(picoContainer.RegisterComponent(new SetterInjectionComponentAdapter( typeof(PurseBean), typeof(MoneyPurse), new IParameter[] { ComponentParameter .DEFAULT, new ConstantParameter (100.0D) }))); }
public void PicoIssue52() { IMutablePicoContainer pico = CreatePicoContainer(); pico.RegisterComponentImplementation("foo", typeof(JMSService), new IParameter[] { new ConstantParameter("0"), new ConstantParameter("something"), }); JMSService jms = (JMSService)pico.GetComponentInstance("foo"); Assert.AreEqual("0", jms.serverid); Assert.AreEqual("something", jms.path); }
public void DuplicateRegistration() { try { IMutablePicoContainer pico = CreatePicoContainer(); pico.RegisterComponentImplementation(typeof(object)); pico.RegisterComponentImplementation(typeof(object)); Assert.Fail("Should have failed with duplicate registration"); } catch (DuplicateComponentKeyRegistrationException e) { Assert.IsTrue(e.DuplicateKey == typeof(object)); } }
public void WillOmitSelfFromCollection() { IMutablePicoContainer pico = GetDefaultPicoContainer(); pico.RegisterComponentImplementation(typeof(SimpleTouchable)); pico.RegisterComponentImplementation(typeof(TouchableObserver)); ITouchable observer = (ITouchable)pico.GetComponentInstanceOfType(typeof(TouchableObserver)); Assert.IsNotNull(observer); observer.Touch(); SimpleTouchable touchable = (SimpleTouchable)pico.GetComponentInstanceOfType(typeof(SimpleTouchable)); Assert.IsTrue(touchable.WasTouched); }
public void ComponentsAreStartedBreadthFirstAndStoppedDepthFirst() { IMutablePicoContainer parent = new DefaultPicoContainer(); parent.RegisterComponentImplementation("recording", typeof(StringBuilder)); parent.RegisterComponentImplementation(typeof(A)); IMutablePicoContainer child = parent.MakeChildContainer(); child.RegisterComponentImplementation(typeof(B)); parent.Start(); parent.Stop(); Assert.AreEqual("<A<BB>A>", parent.GetComponentInstance("recording").ToString()); }
public void UpDownDependenciesCannotBeFollowed() { IMutablePicoContainer parent = CreatePicoContainer(); IMutablePicoContainer child = CreatePicoContainer(parent); // ComponentF -> ComponentA -> ComponentB+ComponentC child.RegisterComponentImplementation(typeof(ComponentF)); parent.RegisterComponentImplementation(typeof(ComponentA)); child.RegisterComponentImplementation(typeof(ComponentB)); child.RegisterComponentImplementation(typeof(ComponentC)); // This should fail child.GetComponentInstance(typeof(ComponentF)); }
public void RegisterComponentWithObjectBadType() { IMutablePicoContainer pico = CreatePicoContainer(); try { pico.RegisterComponentInstance(typeof(IList), new Object()); Assert.Fail("Shouldn't be able to register an Object.class as IList because it is not, " + "it does not implement it, Object.class does not implement much."); } catch (AssignabilityRegistrationException) { } }
public void AmbiguousResolution() { IMutablePicoContainer pico = CreatePicoContainer(); pico.RegisterComponentImplementation("ping", typeof(string)); pico.RegisterComponentInstance("pong", "pang"); try { pico.GetComponentInstance(typeof(string)); } catch (AmbiguousComponentResolutionException e) { Assert.IsTrue(e.Message.IndexOf("System.String") != -1); } }
public SampleTaskBuilder(WeSayWordsProject project, ICurrentWorkTask currentWorkTask, IRecordListManager recordListManager) { _picoContext = CreateContainer(); _picoContext.RegisterComponentInstance("Project", project); _picoContext.RegisterComponentInstance("Current Task Provider", currentWorkTask); _picoContext.RegisterComponentInstance("Record List Manager", recordListManager); string[] analysisWritingSystemIds = new string[] { project.WritingSystems.AnalysisWritingSystemDefaultId }; string[] vernacularWritingSystemIds = new string[] {project.WritingSystems.VernacularWritingSystemDefaultId}; ViewTemplate viewTemplate = new ViewTemplate(); viewTemplate.Add(new Field(Field.FieldNames.EntryLexicalForm.ToString(), vernacularWritingSystemIds)); viewTemplate.Add(new Field(Field.FieldNames.SenseGloss .ToString(), analysisWritingSystemIds)); viewTemplate.Add(new Field(Field.FieldNames.ExampleSentence.ToString(), vernacularWritingSystemIds)); viewTemplate.Add(new Field(Field.FieldNames.ExampleTranslation.ToString(), analysisWritingSystemIds)); _picoContext.RegisterComponentInstance("Default Field Inventory", viewTemplate); }
protected override void ComposeContainer(IMutablePicoContainer container, IList assemblies) { IList registerTypes = FindTypesToRegister(assemblies); foreach(Type type in registerTypes) { IComponentAdapter componentAdapter = null; RegisterWithContainerAttribute attribute = type.GetCustomAttributes(registerAttributeType, true)[0] as RegisterWithContainerAttribute; if(attribute.ComponentAdapterType == ComponentAdapterType.Custom) { componentAdapter = BuildCustomComponentAdapter(attribute, type); } else { componentAdapter = BuildComponentAdapter(attribute, type); } container.RegisterComponent(componentAdapter); } }
public DefaultReflectionContainerAdapter(IMutablePicoContainer picoContainer) { this.picoContainer = picoContainer; }
protected override IComponentAdapter prepINS_errorIsRethrown(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); return new SetterInjectionComponentAdapter(typeof (Ghost), typeof (Ghost), new IParameter[] {ComponentParameter.DEFAULT}); }
protected override IComponentAdapter prepINS_createsNewInstances(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); return new SetterInjectionComponentAdapter(typeof (PersonBean), typeof (PersonBean), new IParameter[] {ComponentParameter.DEFAULT}); }
protected override IComponentAdapter prepINS_createsNewInstances(IMutablePicoContainer picoContainer) { return new ConstructorInjectionComponentAdapter(typeof (SimpleTouchable), typeof (SimpleTouchable)); }
public DefaultNanoContainer(Assembly assembly, IMutablePicoContainer picoContainer) { AddAssembly(assembly); this.picoContainer = picoContainer; }
public AbstractDelegatingMutablePicoContainer(IMutablePicoContainer delegateContainer) { this.delegateContainer = delegateContainer; }
protected override IComponentAdapter prepRES_dependenciesAreResolved(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof (PersonBean)); return new SetterInjectionComponentAdapter(typeof (PurseBean), typeof (PurseBean), new IParameter[] {ComponentParameter.DEFAULT}); }
protected override IComponentAdapter prepRES_failingInstantiationWithCyclicDependencyException(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); picoContainer.RegisterComponentImplementation(typeof (PersonBean), typeof (WealthyPerson)); return picoContainer.RegisterComponent(new SetterInjectionComponentAdapter( typeof (PurseBean), typeof (PurseBean), new IParameter[] {ComponentParameter.DEFAULT})); }
protected override void ComposeContainer(IMutablePicoContainer container, IList assemblies) { // do nothing. assume that this is done in createContainer(). }
protected override IComponentAdapter prepINS_normalExceptionIsRethrownInsidePicoInvocationTargetInitializationException( IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); return new SetterInjectionComponentAdapter( typeof (HidingPersion), typeof (HidingPersion), new IParameter[] {ComponentParameter.DEFAULT}); }
protected override IComponentAdapter prepSER_isSerializable(IMutablePicoContainer picoContainer) { return new InstanceComponentAdapter("Key", 4711); }
protected override IComponentAdapter prepVER_verificationFails(IMutablePicoContainer picoContainer) { return new ConstructorInjectionComponentAdapter(typeof (DependsOnTouchable), typeof (DependsOnTouchable)); }
protected override IComponentAdapter prepDEF_verifyWithoutDependencyWorks(IMutablePicoContainer picoContainer) { return new InstanceComponentAdapter("foo", "bar"); }
public DefaultNanoContainer(Assembly assembly) : this(assembly, new DefaultPicoContainer()) { AddAssembly(assembly); this.picoContainer = new DefaultPicoContainer(); }
protected override IComponentAdapter prepSER_isSerializable(IMutablePicoContainer picoContainer) { return new ConstructorInjectionComponentAdapter(typeof (SimpleTouchable), typeof (SimpleTouchable)); }
public DefaultNanoContainer(IMutablePicoContainer picoContainer) : this(Assembly.GetCallingAssembly(), picoContainer) { }
protected override IComponentAdapter prepDEF_verifyDoesNotInstantiate(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentInstance("Pico Container"); return new SetterInjectionComponentAdapter(typeof (DeadBody), typeof (DeadBody), new IParameter[] {ComponentParameter.DEFAULT}); }
protected abstract void ComposeContainer(IMutablePicoContainer container, Object assemblyScope);
protected override IComponentAdapter prepDEF_verifyDoesNotInstantiate(IMutablePicoContainer picoContainer) { picoContainer.RegisterComponentImplementation(typeof (A)); return new ConstructorInjectionComponentAdapter(typeof (B), typeof (B)); }
protected override IComponentAdapter prepDEF_verifyDoesNotInstantiate( IMutablePicoContainer picoContainer) { return new InstanceComponentAdapter("Key", 4711); }
protected override IComponentAdapter prepINS_errorIsRethrown(IMutablePicoContainer picoContainer) { return new ConstructorInjectionComponentAdapter(typeof (Erroneous), typeof (Erroneous)); }
protected abstract void ComposeContainer(IMutablePicoContainer container, IList assemblies);
protected override IComponentAdapter prepDEF_verifyWithoutDependencyWorks(IMutablePicoContainer picoContainer) { return new ConstructorInjectionComponentAdapter("foo", typeof (A)); }