我在项目中使用 Autofac 和 WCF 集成。我试图找出一种延迟初始化数据协定代理集合属性的方法,以避免通过网络传输整个对象图。
我目前的计划是在每个反序列化数据合约中注入 WCF 服务,以便他们调用该服务,获取集合属性数据并对其进行初始化。
我的问题是:有没有办法告诉 Autofac 在客户端反序列化的每个数据合约代理中注入服务?就像一些调整DataContractSerializer
或什么的。
(没有服务定位器,请...)
谢谢!
Unfortunately there is nothing like this available "out of the box" with Autofac. There is something similar in Autofac's MVC integration, but that's because MVC has a more specific integration point for that sort of thing (IActionInvoker
).
You might be able to write a custom client-side behavior that intercepts certain known types (like collections) on the client and swaps in a lazy-initialized collection. There's a similar question here asking about how to swap the DataContractSerializer
out at runtime. You could use a mechanism like that.