-
-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Description
When using Diagnostic() Extension and a run-time configured InjectionMethod the following exception will be thrown when trying to BuildUp an existing Object.
"System.ArgumentException: Injected method SetDependencies() could not be matched with any public methods on type MyClassWithoutAttribute"
An alternatively usage of [InjectionMethod] Attribute however works as expected .
public interface ISomeInterface { }
public class SomeImpl : ISomeInterface { }
public class MyClassWithAttribute
{
[InjectionMethod]
public void SetDependencies(ISomeInterface some) { }
}
public class MyClassWithoutAttribute
{
public void SetDependencies(ISomeInterface some) { }
}
[TestClass]
public class InjectionMethodIssue
{
[TestMethod]
// Usage of run-time configuration with 'InjectionMethod' throws an exception
public void TestWithoutAttributeAndDiagnostic()
{
var container = new UnityContainer().AddExtension(new Diagnostic());
container.RegisterType<ISomeInterface, SomeImpl>();
container.RegisterType<MyClassWithoutAttribute>(new InjectionMethod("SetDependencies"));
var instance = new MyClassWithoutAttribute();
container.BuildUp(instance);
}
[TestMethod]
// Usage of [InjectionMethod] Attribute instead run-time config works (OK)
public void TestWithAttributeAndDiagnostic()
{
var container = new UnityContainer().AddExtension(new Diagnostic());
container.RegisterType<ISomeInterface, SomeImpl>();
var instance = new MyClassWithAttribute();
container.BuildUp(instance);
}
[TestMethod]
// Run-time config WITHOUT Diagnostic also works (OK)
public void TestWithoutAttributeAndWithoutDiagnostic()
{
var container = new UnityContainer();
container.RegisterType<ISomeInterface, SomeImpl>();
container.RegisterType<MyClassWithoutAttribute>(new InjectionMethod("SetDependencies"));
var instance = new MyClassWithoutAttribute();
container.BuildUp(instance);
}
}
Metadata
Metadata
Assignees
Labels
No labels