WCF Ria DomainService - 在启动时初始化 WebService
目前,每次客户端连接到我的 DomainService 时,都会执行资源的初始化。每个客户端都应该访问该资源的同一实例。 我想在 WebService 的启动时初始化此资源。 WCF Ria 服务有机会做到这一点吗?
编辑: 好吧,不提这个了。我想将其用于全局 DbContext 对象。无论如何,这不是一个好主意,因为 HttpApplication 管理多个线程,它们会同时访问 DbContext。我将把我的实现更改为“每个线程”或“每个 HttpContext”方法。无论如何,谢谢。
Currently, my DomainService does perform an Initialization of a resource everytime a client is connecting to him. Every client should access the same instance of this resource.
I would like to initialize this resource on the StartUp of the WebService. Is there any chance to do that with WCF Ria Services?
EDIT:
Okay, don't mention it. I wanted to use this for an global DbContext object. This isn't a good idea anyway, because there will be multiple threads managed by the HttpApplication which would access the DbContext simultaneously. I will change my implementation to an "per Thread", respectively "per HttpContext", approach. Thanks anyhow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以定义一个包含该资源的静态属性的类。然后,您可以在 DomainService 中访问该属性。只有在第一次访问时才会对其进行初始化。
示例:
在 DomainService 中:
如果您想在 Service 启动时初始化它,那么您应该能够在
Global
类中执行此操作。You can define a class that contains a static property for that resource. In the DomainService you can then access that property. It would then be initialized only when it is accessed the first time.
Example:
In the DomainService:
If you want to initialize it when the Service is started, then you should be able to do that in the
Global
class.