2009-05-23 153 views
6

我有一堆實現各種接口的服務。例如,IAlbumServiceIMediaServiceStructureMap攔截器

我想登錄到這些接口上的每個方法調用。我如何使用StructureMap來做到這一點?

我意識到這與這個question幾乎相同,只是我沒有使用windsor。

回答

2

我認爲您正在尋找this answer

static void Main() 
{ 
    ObjectFactory.Configure(x => 
    { 
     x.For<Form>().Use<Form1>() 
      .InterceptWith(new ActivatorInterceptor<Form1>(y => Form1Interceptor(y), "Test")); 
    }); 
    Application.Run(ObjectFactory.GetInstance<Form>()); 

} 

public static void Form1Interceptor(Form f) 
{ 
    //Sets the title of the form window to "Testing" 
    f.Text = "Testing"; 
} 

我不會在真正的應用程序中使用ObjectFactory,但至少這個概念在那裏。

+0

不錯!我不敢相信你終於回答了我5歲的老問題:-)幸好我沒有失去對此的任何沉睡,實際上我甚至不記得它是什麼樣的! – 2014-12-02 15:04:48