public void WhenEnumTypeIsProvidedForIntParameterConversionWillBeAttempted() { var ci = typeof(CtorWithInt).GetTypeInfo().DeclaredConstructors.Single(); var cpb = new ConstructorParameterBinding( ci, new[] { new PositionalParameter(0, Foo.B), }, new ContainerBuilder().Build()); var instance = (CtorWithInt)cpb.Instantiate(); Assert.Equal(1, instance.Value); }
public void WhenAnExceptionIsThrownFromAConstructor_TheInnerExceptionIsWrapped() { var ci = typeof(ThrowsInCtor).GetTypeInfo().DeclaredConstructors.Single(); var cpb = new ConstructorParameterBinding( ci, Enumerable.Empty <Parameter>(), new ContainerBuilder().Build()); var dx = Assert.Throws <DependencyResolutionException>(() => cpb.Instantiate()); Assert.True(dx.Message.Contains(typeof(ThrowsInCtor).Name)); Assert.Equal(ThrowsInCtor.Message, dx.InnerException.Message); }
public void WhenAnExceptionIsThrownFromAConstructor_TheInnerExceptionIsWrapped() { var ci = typeof(ThrowsInCtor).GetConstructor(new Type[0]); var cpb = new ConstructorParameterBinding( ci, Enumerable.Empty <Parameter>(), Container.Empty); var dx = Assert.Throws <DependencyResolutionException>(() => cpb.Instantiate()); Assert.That(dx.Message.Contains(typeof(ThrowsInCtor).Name)); Assert.AreEqual(ThrowsInCtor.Message, dx.InnerException.Message); }
public T Get <T>(params object[] args) where T : class { ConstructorInfo ci = this.GetConstructorInfo(args); if (ci == null) { throw ... } var binder = new ConstructorParameterBinding(ci, args, this._scope); T value = binder.Instanciate() as T; if (value == null) { throw ... } if (value is IDisposable) { this._scope.Disposer.AddInstanceForDisposal(value); } return(value); }