0

I am trying to figure out if it's possible to use the <replaced-method> and an object implementing IMethodReplacer in spring.Net to swap out a getter in C#? In this case I have to go this route because the property being injected is a calculated value--am I going to have to make the getter into an actual method?

Here is a skeleton of what I'm trying to do:

public class SecureHeader
{
    public string Token { get; set; }
}

public class Generator
{
    public SecureHeader GenerateSecureHeader(object[] args) { return new SecureHeader(); }
}

public class InstantiatedByIOC
{
    public virtual SecureHeader Header
    {
        get
        {
            return new SecureHeader
            {
                Token = "Hard Coded"
            };
        }
    }
}

public class SecureHeaderReplacer : IMethodReplacer
{
    public Generator Generator { get; set; }
    public object Implement(object target, MethodInfo method, object[] args)
    {
        return Generator.GenerateSecureHeader(null);
    }
}

How would I go about wiring this up (I keep getting an Invalid method override :D)?

The following doesn't work:

<object id="replacer" type="SecureHeaderReplacer">
   <property name="Generator" ref="CreatedElsewhere"/>
</object>
<object id="entityToInject type="InstantiatedByIOC">
   <replaced-method name="Header replacer="replacer">
      <arg-type match="SecureHeader" />
   </replaced-method>
</object>

Any

4

1 回答 1

1

....通过反射器查看代码后,我可以使用类似的东西:

<object id="entityToInject" type="InstantiatedByIOC">
   <replaced-method name="get_Header" replacer="replacer"/>
</object>
于 2013-07-15T20:37:54.923 回答