使用 NHibernate 在延迟加载场景中使用 Castle.DynamicProxy 实现 IDataErrorInfo
我已经使用 Castle.DynamicProxy IIterceptor 实现了 IDataErrorInfo 接口。我还实现了一个 NHibernate 拦截器,它使用该拦截器实例化我的实体。问题在于延迟加载的实体。这些是使用 nhibernate 配置文件中指定的代理工厂类构造的,它显然不提供 IDataErrorInfo 实现。该代理通过我的拦截器掩盖了 IDataErrorInfo 的底层实现,这导致验证失败。
这个问题有哪些可能的解决方案?
(解决该问题的一种方法是更改 nhibernate 使用的默认代理工厂。)
I have implemented IDataErrorInfo interface using Castle.DynamicProxy IIterceptor. I have also implemented a NHibernate interceptor which instantiates my entities using this interceptor. The problem is with lazy loaded entities. These are constructed using a proxy factory class specified in nhibernate config file, which obviously does not provide IDataErrorInfo implementation. This proxies are masking the underlying implementation of IDataErrorInfo by my interceptor which causes the validation to fail.
What are the posible solutions of this problem?
(One way to solve the problem would be to change the default proxy factory which nhibernate uses.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种解决方案是覆盖默认的 Castle 代理工厂并使用 IDataErrorInfo 扩展接口数组。 LazyInitializer 实际上并没有实现这个接口,它只是将调用转发到我们自己的代理实现。然后,
DataBindingProxyFactory
必须注册为 NHibernate 代理工厂。One solution is to override the default Castle proxy factory and extend the interfaces array with IDataErrorInfo. The LazyInitializer does not actualy implement this interface, it only forwards calls to our own proxy implementation. The
DataBindingProxyFactory
must then be registered as NHibernate proxy factory.