I am working on an implementation of log interceptor using Castle Dynamic Proxy and StructureMap, so in my dependency registry I tell to StructureMap to decorate all instance of TrafficSourceRepository with a LoggingInterceptor.
var proxyGenerator = new ProxyGenerator();
For<ITrafficSourceRepository>(Lifecycles.Singleton)
.DecorateAllWith(instance => proxyGenerator
.CreateInterfaceProxyWithTargetInterface(instance,
new LoggingInterceptor(LogManager.GetLogger("AgencyPlayground"))))
.Use<TrafficSourceRepository>();
All seems to be fine, it works, but the TrafficSourceRepository will be instanciated as a Singleton
, and I don't want to, so I change the lifetime of the resolved TrafficSourceRepositories as Transient
:
var proxyGenerator = new ProxyGenerator();
For<ITrafficSourceRepository>(Lifecycles.Transient)
.DecorateAllWith(instance => proxyGenerator
.CreateInterfaceProxyWithTargetInterface(instance,
new LoggingInterceptor(LogManager.GetLogger("AgencyPlayground"))))
.Use<TrafficSourceRepository>();
and it doesn't work anymore... It is a bug or I am doing something wrong?