StructureMap 拦截器

发布于 2024-07-21 21:26:13 字数 310 浏览 1 评论 0原文

我有很多实现各种接口的服务。 例如,IAlbumServiceIMediaService 等。

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

我意识到这与问题只是我没有使用温莎。

I have a bunch of services that implement various interfaces. eg, IAlbumService, IMediaService etc.

I want to log calls to each method on these interfaces. How do I do this using StructureMap?

I realise this is pretty much the same as this question it is just that I am not using windsor.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏见 2024-07-28 21:26:13

我认为您正在寻找这个答案

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,但至少有这个概念。

I think you are looking for 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";
}

I wouldn't use ObjectFactory in a real application, but at least the concept is there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文