如何将拦截器添加到温莎城堡的类型化工厂设施工厂方法中
我正在温莎城堡使用类型化工厂设施。当工厂方法生成它应该创建的实例时,我想得到一个回调,以便连接该实例以获取属性更改通知。这样我就不需要确保在调用工厂方法之后调用这个“创建后”步骤,而是将此责任交给工厂。
有没有办法使用类型化工厂设施或其他 Castle 功能在生成的工厂上注册回调或在工厂上创建用于执行回调的拦截器?
I'm using a Typed Factory Facility in Castle Windsor. I want to get a callback when a factory method generates an instance of what it is supposed to create in order to wire up the instance for property change notification. This way I won't need to ensure this "post-creation" step is called after calling the factory method, instead giving this responsibility to the factory.
Is there a way, either using the Typed Factory Facility or some other Castle feature to register a callback on the generated factory or create an interceptor on the factory which is used to perform the callback?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以通过从 AbstractFacility 派生创建 Facility 来解决此问题。注册到 Kernel.ComponentCreated 事件并检查创建的组件是否需要属性更改通知。如果是这样注册。
您可以使用 ComponentDestroyed 事件来确保您也能很好地注销。下面是我使用 Caliburn.Micro 事件聚合器自动注册视图模型的代码片段
谨致问候,
马尔温。
You can probably solve this by creating a Facility by deriving from AbstractFacility. Register to the Kernel.ComponentCreated event and check whether the created component needs the property changed notification. If so register.
You can use the ComponentDestroyed event to make sure you also nicely unregister. Below a code snippet I use to auto register view models with Caliburn.Micro's event aggregator
Kind regards,
Marwijn.