Search code examples
c#inversion-of-controlstructuremapcastle-dynamicproxy

Should Castle DynamicProxy IInterceptor or ProxyGenerator be cached?


I'm using StructureMap to Enrich some of my objects with an instance call to

ProxyGenerator.CreateInterfaceProxyWithTarget(myObject, MYInterceptor)

Currently I have the MYInterceptor inside my container, should I implement any type of caching for the interceptor?

The second question should I register my ProxyGenerator inside my container and if so, should I apply any type of caching to it?


Solution

  • you most likely want to reuse the same ProxyGenerator to take advantage of its proxy type caching capabilities.

    About the interceptor - it depends. Is it purely functional? Does it have its own state? There's no general rule for that, so you need to decide whether you need a new instance for each new proxy, or can the same instance be reused (which makes sense almost exclusively when interceptor has no state on its own)