Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/TinyIoC.Tests/TinyIoCFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public void NestedClassDependencies_CorrectlyRegistered_ResolvesRoot()
Assert.IsInstanceOfType(result, typeof(NestedClassDependencies.RootClass));
}

[TestMethod]
public void NestedClassDependencies_UsingConstructorFromAnotherType_ThrowsException()
{
var container = UtilityMethods.GetContainer();
var registerOptions = container.Register<NestedClassDependencies.RootClass>();

AssertHelper.ThrowsException<TinyIoCConstructorResolutionException>
(() => registerOptions.UsingConstructor(() => new RootClass(null, null)));
}

[TestMethod]
public void NestedClassDependencies_MissingService3Registration_ResolvesRootResolutionOn()
{
Expand Down
3 changes: 3 additions & 0 deletions src/TinyIoC/TinyIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,9 @@ public RegisterOptions WithStrongReference()
#if EXPRESSIONS
public RegisterOptions UsingConstructor<RegisterType>(Expression<Func<RegisterType>> constructor)
{
if(!IsValidAssignment(_Registration.Type, typeof(RegisterType)))
throw new TinyIoCConstructorResolutionException(typeof(RegisterType));

var lambda = constructor as LambdaExpression;
if (lambda == null)
throw new TinyIoCConstructorResolutionException(typeof(RegisterType));
Expand Down