Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StructureMap Interceptors

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.

like image 275
Derek Ekins Avatar asked May 23 '09 20:05

Derek Ekins


1 Answers

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.

like image 93
NightOwl888 Avatar answered Oct 18 '22 05:10

NightOwl888