代码之家  ›  专栏  ›  技术社区  ›  Derek Ekins

结构图拦截器

  •  6
  • Derek Ekins  · 技术社区  · 17 年前

    我有一系列实现各种接口的服务。如, IAlbumService , IMediaService

    我想记录对这些接口上每个方法的调用。如何使用StructureMap进行此操作?

    我意识到这和这差不多 question

    1 回复  |  直到 8 年前
        1
  •  2
  •   Community Mohan Dere    9 年前

    我想你在找我 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,但至少它的概念是存在的。

    推荐文章