을 우선 할 원하는
같은, 당신은 유니티를 사용하여 정적 방법을 요격 할 수 없습니다.
Developer's Guide to Dependency Injection Using Unity을 살펴보십시오. 특히, Interception using Unity에있는 장. 가이드의 코드를 수정하고 조정하면 다음과 같이 될 수 있습니다.
class CustomExceptionHandler : ICallHandler
{
public IMethodReturn Invoke(IMethodInvocation input,
GetNextHandlerDelegate getNext)
{
WriteLog(String.Format("Invoking method {0} at {1}",
input.MethodBase, DateTime.Now.ToLongTimeString()));
// Invoke the next handler in the chain
var result = getNext().Invoke(input, getNext);
// After invoking the method on the original target
if (result.Exception != null)
{
// This could cause an exception if the Type is invalid
result.ReturnValue = -1;
result.Exception = null;
}
return result;
}
public int Order
{
get;
set;
}
}
class CustomExceptionHandlerAttribute : HandlerAttribute
{
private readonly int order;
public CustomExceptionHandlerAttribute(int order)
{
this.order = order;
}
public override ICallHandler CreateHandler(IUnityContainer container)
{
return new CustomExceptionHandler() { Order = order };
}
}
class TenantStore : ITenantStore
{
[CustomExceptionHandler(1)]
public int Process()
{
throw new Exception("TEST");
}
}
container.RegisterType<ITenantStore, TenantStore>(
new InterceptionBehavior<PolicyInjectionBehavior>(),
new Interceptor<InterfaceInterceptor>());
첫 번째로, Unity를 사용하여 정적 메소드를 인터셉트 할 수 없습니다. >>>> 이것은 좋지 않습니다. 어떻게 AOP를 구현할 수 있을지 모르겠다. 포스트 샤프와 같은 기능을 갖춘 무료 솔루션이 필요합니다. –
[Afterthough] (http://github.com/vc3/Afterthought)을 볼 수 있습니다. 거기에 많은 무료 대안이 없습니다. –