2010-09-16 58 views
0

我有一個項目Company.Business,我試圖用PostSharp來包裝我的業務層。在項目Company.AOP,我有一個方法邊界方面使用EL測井應用程序塊這樣:PostSharp - 我在做什麼錯?

[Serializable] 
public class MethodExcecutionAttribute : OnMethodBoundaryAspect 
{ 
    public override void OnEntry(MethodExecutionEventArgs eventArgs) 
    { 
     base.OnEntry(eventArgs); 

     //Log message 
    } 

    public override void OnException(MethodExecutionEventArgs eventArgs) 
    { 
     base.OnException(eventArgs); 

     //Log message 
    } 

    public override void OnExit(MethodExecutionEventArgs eventArgs) 
    { 
     base.OnExit(eventArgs); 

     //Log message 
    } 
} 

夠簡單;它只是記錄了時間點。我試着通過指定我的整個業務層:

[assembly: MethodExcecution(AttributeTargetTypes = "*", 
    AttributeTargetAssemblies = "Company.Business", 
    AttributeTargetTypeAttributes = MulticastAttributes.Public, 
    AttributeTargetMemberAttributes = MulticastAttributes.Public)] 

但編譯後,我檢查DLL,它不換行代碼在網站上的例子。這種方法有什麼問題?

我確實安裝了它,並驗證它正在運行;它在編譯時產生輸出,沒有錯誤。

謝謝。

回答

2

當前版本中存在一個錯誤:如果指定了AttributeTargetAssemblies,它只會看到程序集引用,而不是當前項目。

所以,如果你想添加方面到當前項目,刪除AttributeTargetAssemblies。

+0

那麼我需要那麼在同一個項目中有我所針對的方面,或者該DLL中的Company.AOP方面是以公司的。Business組件爲目標的方式?我很困惑。謝謝。 – 2010-09-17 02:38:02