Castle DynamicProxy 生成的类名
有谁知道是否可以控制通过 Castle DynamicProxy 生成的类型的名称?我希望利用保留 Castle 生成的程序集的能力,向我的项目添加一些具有某些特定功能的附加类,但我希望能够控制这些生成的代理类型的名称。任何帮助将不胜感激。
实际上,我计划保留这些类的实例以及作为 NHibernate 代理来源的原始类的实例。因此,我需要这些名称在程序集的多代中保持一致。
Does anybody know if it is possible to control the names of the types generated through Castle DynamicProxy? I was hoping to take advantage of the ability to persist the assembly generated by Castle to add some additional classes with some specific functionality to my project, but I would like to be able to control the names of these generated proxy types. Any help would be greatly appreciated.
I actually plan to persist instances of these classes as well as instances of the original classes that are the sources of the proxies with NHibernate. So, I need these names to be consistent across multiple generations of the assembly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我做了一些有趣的挖掘。使用 INamingScope 似乎可以指定代理名称,但插入 INamingScope 远非那么简单。您需要创建自己的 ProxyFactoryFactory,这将创建一个与 NHibernate.ByteCode.Castle.ProxyFactory 相同的 ProxyFactory,除了它会初始化 ProxyGenerator:
老实说,我还没有尝试过运行或编译其中任何一个。只是深入研究 NHibernate 和 Castle.Core 源代码。希望它能给你一些想法......
I did some interesting digging. Specifying proxy names appears to be possible using an INamingScope, but it is far from straightforward to get the INamingScope wedged in. You would need to create your own ProxyFactoryFactory, which would create a ProxyFactory identical to NHibernate.ByteCode.Castle.ProxyFactory, except it would initilize ProxyGenerator:
I honestly haven't tried running or compiling any of this. Just digging through the NHibernate and Castle.Core source code. Hopefully it gives you some ideas...
看一下 NHContrib 中的 ProxyGenerators 项目。它允许您预先生成 NHibernate 的延迟加载代理。
http://nhforge.org/wikis/proxygenerators10/default.aspx
是否使用无论是否有 ProxyGenerator,您都可以通过 Proxy Factory 将自定义代理集成到 NHibernate 中。在 hibernate.cfg.xml 中:
Take a look at the ProxyGenerators project in NHContrib. It allows you to pre-generate NHibernate's lazy loading proxies.
http://nhforge.org/wikis/proxygenerators10/default.aspx
Whether you use the ProxyGenerators or not, you integrate your custom proxies into NHibernate via the Proxy Factory Factory. In hibernate.cfg.xml: