HandlerAttribute. , Unity , - HandlerAttribute , Unity .
, , , . , , : -
public class MyCallHandler : ICallHandler
{
public MyCallHandler(Int32 value)
{
Order = value;
}
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Console.WriteLine("Parameterised call handler!");
return getNext()(input, getNext);
}
public int Order { get; set; }
}
CustomTagAttribute HandlerAttribute: -
public class MyHandler : HandlerAttribute
{
private readonly Int32 value;
public MyHandler(Int32 value)
{
this.value = value;
}
public override ICallHandler CreateHandler(IUnityContainer container)
{
return new MyCallHandler(value);
}
}
MyHandler . CreateHandler, MyCallHandler: -
public class MyClass
{
[MyHandler(2)]
public virtual void Foo()
{
Console.WriteLine("Inside method!");
}
}
, , ICallHandler, HandlerAttribute ( "this").
, - HandlerAttribute, , , .
, , , , .