StructureMap Interceptors
Asked Answered
E

1

6

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.

Endoscope answered 23/5, 2009 at 20:12 Comment(0)
C
2

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.

Cerebrum answered 29/11, 2014 at 11:57 Comment(1)
Nice one! I can't believe you've finally answered my 5yr old question :-) thankfully I haven't been loosing any sleep over this, in fact I can't even remember what it was for!Endoscope

© 2022 - 2024 — McMap. All rights reserved.