Permalink
4aa8884 Jun 13, 2018
@stakx @jonorossi
31 lines (23 sloc) 2.81 KB

Castle DynamicProxy

DynamicProxy generates proxies for your objects that you can use to transparently add or alter behavior to them, provide pre/post processing and many other things. Following are just a few better known and popular usages of DynamicProxy:

  • Castle Windsor uses proxies to enable its interception capabilities and for typed factories
  • Moq uses it to provide "the most popular and friendly mocking framework for .NET"
  • NSubstitute uses it to provide "a friendly substitute for .NET mocking frameworks"
  • FakeItEasy uses it to provide "the easy mocking library for .NET"
  • Rhino Mocks uses it to provide "a dynamic mock object framework for the .NET platform"
  • NHibernate uses it to provide lazy loading capabilities (pre-v4.0)
  • Entity Framework Core uses it in its package Microsoft.EntityFrameworkCore.Proxies to provide lazy-loading proxies

If you're new to DynamicProxy you can read a quick introduction, browse through description of the core types in the library, or go into more advanced, in detail discussion:

ℹ️ Where is Castle.DynamicProxy.dll?: DynamicProxy used to live in its own assembly. As part of changes in version 2.5 it was merged into Castle.Core.dll and that's where you'll find it.

⚠️ Use of a single ProxyGenerator's instance: If you have a long running process (web site, windows service, etc.) and you have to create many dynamic proxies, you should make sure to reuse the same ProxyGenerator instance. If not, be aware that you will then bypass the caching mechanism. Side effects are high CPU usage and constant increase in memory consumption.

See also