public void Component_With_Property_Dependencies_Resolves_As_Expected() { // arrange ResolvableProperty prop = new ResolvableProperty("placeOfBirth"); var registration = new PropertyResolvingComponentRegistration <ICanBePerson>() .DependsOn(prop) .ImplementedBy <Person>(); // act m_container.Register(registration); // assert Person person = (Person)m_container.Resolve <ICanBePerson>(); Assert.IsNull(person.Name); Assert.AreEqual(0, person.PersonAge); Assert.AreEqual("Pune", person.PlaceOfBirth); }
public void Component_With_No_Lifestyle_Registers_As_Singleton() { // arrange ResolvableProperty prop = new ResolvableProperty("placeOfBirth"); var registration = new PropertyResolvingComponentRegistration <ICanBePerson>() .DependsOn(prop) .ImplementedBy <Person>(); // act m_container.Register(registration); // assert Person person1 = (Person)m_container.Resolve <ICanBePerson>(); Person person2 = (Person)m_container.Resolve <ICanBePerson>(); // since we have not specified the lifestyle, the container should return the same instance // therefore hashcode should be equal for both instances Assert.AreEqual(person1.GetHashCode(), person2.GetHashCode()); }
public void Component_With_LifestyleDescriptor_Overrides_Default_Lifestyle() { // arrange ResolvableProperty prop = new ResolvableProperty("placeOfBirth"); var registration = new PropertyResolvingComponentRegistration <ICanBePerson>() .DependsOn(prop) .ImplementedBy <Person>(); // now override lifestyle with a descriptor registration.AddDescriptor(new LifestyleDescriptor <ICanBePerson>(LifestyleType.Transient)); // act m_container.Register(registration); // assert Person person1 = (Person)m_container.Resolve <ICanBePerson>(); Person person2 = (Person)m_container.Resolve <ICanBePerson>(); // since we have overridden the lifestyle, the container should generate 2 instances // therefore hashcode should be different for both instances Assert.AreNotEqual(person1.GetHashCode(), person2.GetHashCode()); }