WCF Ria DomainService - 在启动时初始化 WebService

发布于 2024-11-07 17:30:52 字数 279 浏览 0 评论 0原文

目前,每次客户端连接到我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吐个泡泡 2024-11-14 17:30:52

您可以定义一个包含该资源的静态属性的类。然后,您可以在 DomainService 中访问该属性。只有在第一次访问时才会对其进行初始化。

示例:

public class ResManager {
    public static MyObject {...}
}

在 DomainService 中:

public IQueryable<SomeClass> GetSomeObjects()
{
    // you can access it here and it will not be initialized 
    // every time the DomainService is called
    MyObject obj = ResManager.MyObject;
    return new List<SomeClass>().AsQueryable();
}

如果您想在 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:

public class ResManager {
    public static MyObject {...}
}

In the DomainService:

public IQueryable<SomeClass> GetSomeObjects()
{
    // you can access it here and it will not be initialized 
    // every time the DomainService is called
    MyObject obj = ResManager.MyObject;
    return new List<SomeClass>().AsQueryable();
}

If you want to initialize it when the Service is started, then you should be able to do that in the Global class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文