Interception and Lifetime Manager

Feb 10, 2011 at 3:03 PM


When using interception through an interface and a lifetime manager different than transient (or null), its SetValue method receives the original object, not the generated proxy.

Is this the most appropriate solution? Shouldn't it receive the generated proxy?

What do you guys think?



Feb 11, 2011 at 3:26 AM

@%*!% Codeplex ate my response from earlier today.

The current design is the best approach I came up with for an unfortunate combination of things. The lifetime manager is registered for the concrete type, not the interface. So if you have:

    container.RegisterType<IFoo, FooImpl>(new ContainerControlledLifetimeManager());

    var obj1 = container.Resolve<IFoo>();

    var obj2 = container.Resolve<FooImpl>();

    Assert.AreSame(obj1, obj2);

this assert will pass.

The problem is that, with the interface interceptor, the proxy is NOT an instance of the concrete class, it's an instance of the interface. So if you try to put the proxy into the lifetime manager, you'll get all sorts of weird casting exceptions at odd places in the guts of the container, because there's parts that are going to need a FooImpl, and you're handing it the IFoo proxy.