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.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
Derek Ekins
  • 11,215
  • 6
  • 61
  • 71

1 Answers1

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.

Community
  • 1
  • 1
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • 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! – Derek Ekins Dec 02 '14 at 15:04