InjectionMethod w/ Private & Protected Methods

Topics: ObjectBuilder
Jul 30, 2007 at 3:57 PM
I am using the InjectionMethod on a void in my class. If the method is not public, the method will not be executed. Is there a way to force object builder to look for private and protected methods to be executed?

Here is my sample class:

/// <summary>
/// Class demonstrates how to use the InjectionMethodAttribute
/// </summary>
public class ObjectWithMethodInjection
{
public ObjectWithMethodInjection(){}

InjectionMethod
public void SetCount()
{
_count = 4 + 4;
}

private int _count;
public int Count
{
get
{
return _count;
}
set
{
if (_count == value)
return;
_count = value;
}
}
}

Here is my test harness:
TestMethod
public void TestMethodInjection()
{
DependencyContainer container = new DependencyContainer();
ObjectWithMethodInjection obj = container.Get<ObjectWithMethodInjection>();

Assert.IsNotNull(obj);
Assert.IsTrue(obj.Count==8);
}
Jul 30, 2007 at 6:01 PM
All of the reflection strategies in ObjectBuilder do public reflection only by default, for performance and permission reasons (public reflection does not require special permission). Doing private reflection and invocation, we found, could be 10+x slower than public reflection and invocation. Some features, like interception, will likely never work with non-public APIs, owing to what they're doing.

You will need to change the specific reflection strategy (MethodReflectionStrategy, in this case) to support protected/private reflection.
Jul 31, 2007 at 3:12 PM

BradWilson wrote:
You will need to change the specific reflection strategy (MethodReflectionStrategy, in this case) to support protected/private reflection.


Thanks for the direction.