Unity를 AoP 프레임 워크, 특히 VirtualMethodInterceptor + CallHandler로 사용하는 것으로 나타났습니다.AOP 프레임 워크로 Unity를 사용할 때 전체 스택 추적이 누락되었습니다.
내가 얻은 스택 추적에는 원래 코드가 포함되어 있지 않습니다. 대신 xxx_wrapper_yyyy 유형의 클래스가 있는데, 원래 클래스에서 동적으로 상속받는 클래스라고 가정합니다. 동적 클래스에 대해 소스 코드가 작성되지 않았기 때문에 원래 코드에서 오류가 발생한 행 번호를보고하지 않습니다.
어떻게 변경할 수 있습니까? 예외가 throw 된 스택 추적 및 행 번호가 필요합니다.
참고 : 호출 처리기는 달리 의도 한대로 작동합니다. 단지 원래의 가상 메소드의 행 번호가 누락 된 예외입니다. 그리고 호출 핸들러에는 예외를 삼키거나 처리 할 행이 없습니다. 이 코드
[TestMethod]
public void Should_Wrap_Exception_ThrownByTarget()
{
var container = new UnityContainer();
container.RegisterType<Target>(
new Interceptor<VirtualMethodInterceptor>(),
new InterceptionBehavior<PolicyInjectionBehavior>());
container.AddNewExtension<Interception>();
var config = container.Configure<Interception>();
config.AddPolicy("1").AddCallHandler<ExceptionHandler>().AddMatchingRule<AlwaysMatches>();
var target = container.Resolve<Target>();
target.AlwaysThrows("foo");
}
public class AlwaysMatches : IMatchingRule
{
public bool Matches(MethodBase member)
{
return true;
}
}
public class ExceptionHandler : ICallHandler
{
public int Order { get; set; }
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IMethodReturn r = getNext()(input, getNext);
if (r.Exception != null)
{
throw new InvalidOperationException("CallHandler", r.Exception);
}
return r;
}
}
public class Target
{
public virtual string AlwaysThrows(string foo)
{
throw new Exception("Boom!");
}
}
를 사용
시도 내가 AOP가 SOLID하지 그것을 모순 보완 생각 – Steven
몰라 :-) 가로 채기를 사용에서 당신을 저장하는 더 나은 (SOLID) 디자인으로 올라오고. – Alwyn
차단이 필요한 경우 시스템에서 추상화가 누락되었습니다. IMO, 하나의 제네릭 데코레이터로 관련 클래스 세트를 꾸밀 수 있어야합니다. 이렇게하면 가로 채기가 필요하지 않습니다. 예를 들어 [이 기사] (http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=91)를보십시오. – Steven