public void Cyclic_DependencyOverride() { // Arrange Container.RegisterType <I0, G0>() .RegisterType <I1, G1>(); //next line throws StackOverflowException Container.Resolve <G1>( Override.Dependency <I0>( Resolve.Dependency <I1>())); }
public void Overrides_ValueOverrideForTypeDifferentThanResolvedTypeIsIgnored() { // Act var result = Container.Resolve <ObjectWithProperty>( Override.Property(nameof(ObjectWithProperty.MyProperty), Resolve.Dependency <ISomething>(Name)) .OnType <ObjectThatDependsOnSimpleObject>()); // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.MyProperty); Assert.IsInstanceOfType(result.MyProperty, typeof(Something1)); }
public void Overrides_CanOverrideValue() { // Act var result = Container.Resolve <ObjectWithProperty>( Override.Property(nameof(ObjectWithProperty.MyProperty), Resolve.Dependency <ISomething>(Name)) .OnType <ObjectWithProperty>()); // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.MyProperty); Assert.IsInstanceOfType(result.MyProperty, typeof(Something2)); }
public void ParameterOverrideCanResolveOverride() { // Setup Container.RegisterType <IService, Service1>() .RegisterType <IService, Service2>("other"); // Act var result = Container.Resolve <ObjectTakingASomething>( Override.Parameter("something", Resolve.Dependency <IService>("other"))); // Verify Assert.IsInstanceOfType(result.MySomething, typeof(Service2)); }
public void ResolverWithElementsReturnsResolvedElements() { // Arrange object o1 = new object(); object o2 = new object(); object o3 = new object(); Container.RegisterInstance("o1", o1) .RegisterInstance("o2", o2) .RegisterInstance("o3", o3) .RegisterType <InjectedObject>( Invoke.Constructor( Inject.Array(typeof(object), Resolve.Dependency <object>("o1"), Resolve.Dependency <object>("o2")))) .RegisterType <InjectedObject>(Legacy, new InjectionConstructor( new ResolvedArrayParameter(typeof(object), new ResolvedParameter <object>("o1"), new ResolvedParameter <object>("o2")))); // Act var result = (object[])Container.Resolve <InjectedObject>().InjectedValue; var legacy = (object[])Container.Resolve <InjectedObject>().InjectedValue; // Validate Assert.IsNotNull(result); Assert.AreEqual(2, result.Length); Assert.AreSame(o1, result[0]); Assert.AreSame(o2, result[1]); Assert.IsNotNull(legacy); Assert.AreEqual(2, legacy.Length); Assert.AreSame(o1, legacy[0]); Assert.AreSame(o2, legacy[1]); }