WCF 和容器生命周期
我确信这是显而易见的,但我一直无法找到关于 IIS 7.5 托管 WCF 服务中容器生命周期的非常具体、明确的答案。
如果容器位于我的服务代码中,则除非 InstanceContextMode 设置为 single,否则它将在每次请求时创建它? (我知道坏主意)
如果我使用 ServiceHostFactory 和 IInstanceProvider 配置 WCF 以使用容器来解析每次调用的服务对象,InstanceContextMode 将如何工作?这不是取决于容器使用的生命周期策略吗?
如果它是在工厂中创建的单例就足够了,容器不会在每次调用时重新初始化?
谢谢
I'm sure this is obvious but I haven't been able to find a very specific clean answer to the lifetime of a container in a IIS 7.5 hosted WCF service.
If the container lives in my service code, it would be created on every request unless InstanceContextMode is set to single? (I know bad idea)
If I configure WCF using ServiceHostFactory and IInstanceProvider to use a container to resolve the service object on every call how would the InstanceContextMode work? Wouldn't it depend on the lifetime policy used by the container?
If its a singleton created in the factory is that sufficient such that the container won't reinitialize on every call?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将容器托管在自定义 ServiceHostFactory 中,因为只有一个 ServiceHostFactory 实例给定的 WCF 服务。
这确保了容器本身是单个实例,从而使其能够有效地管理所有组件的生命周期。
You should host the container in a custom ServiceHostFactory since there's only a single instance of the ServiceHostFactory for a given WCF service.
This ensures that the container itself is a single instance, thus enabling it to effectively manage lifetime of all components.