How do the POCOs run?


I would like to be able to create a runtime proxy for a POCO, in the same style as I might in Java using the JRE or cglib proxying libraries.

I've seen Castle DynamicProxy which looks like it fits the bill, but the documentation isn't great. I'm also surprised that this kind of thing isn't in the .Net Framework itself.

Does anyone:

  • Know of any good resources for Castle DynamicProxy?
  • Know of any alternative approaches?


This may not be worth much as answers go, but one of the reasons that you don't see a proliferation of dynamic proxies in .NET is that most common .NET languages (C#, VB.NET) differ from Java in one very important aspect:

In Java, all methods are virtual unless explicitly declared sealed.

In C# (and VB.NET IIRC) all methods and properties are sealed unless explicitly declared virtual.

This means that the potential value of a dynamic proxy is far lower in .NET than it is in Java. You have to explicitly design your .NET objects to be 'proxyable', and most people don't do that - it takes a conscious decision to make a .NET object 'proxyable'.

It's actually so rare to see a .NET dynamic proxy outside of DI Containers that I can't think of any other dynamic proxies than Castle.

Note that the 'sealed by default' behavior is a feature of the .NET languages - it is very conceivable that one could design a .NET-based language that has the same 'virtual by default' behavior as Java. Although I don't know any, I would be surprised if such a language does not exist. After all, it's all in the compiler.