Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top