保持相同的 SPWeb 和SPSite 贯穿整个应用程序生命周期?

发布于 2024-11-15 08:01:12 字数 793 浏览 5 评论 0原文

我们有几个项目有很多 DAL。许多共享点列表(例如客户、销售、提供者)都反映在 C# 类中。我们通过抽象母类让每个对象实现IDisposable。例如,每次我们实例化一个对象以从列表中获取客户时,调用者代码都需要调用 customer.Dispose() 来处置用于实例化该对象的 spweb 和 spsite :

 public Customer(int spListItemID):base(LIST_URL)
    {
        try
        {
            spli = Liste.GetItemById(spListItemID);
        }
        catch(ArgumentException)
        {
            spli = null;
        }
    }

并且在构造函数基类中有 spsite和 spweb 全局变量实例化,还有 dispose 函数。

我想知道:对于整个 sharepoint 应用程序使用相同的 spweb 和 spsite 怎么样?我们所有的项目都知道一个可以按照单例模式实例化这些 spsite 和 spweb 的项目。我们将“永远”使用这个 spsite 和 spweb,我们永远不会关闭它们,并对每个对象使用相同的内容,从而在每次实例化对象时保存打开-关闭过程!

你认为这是一个疯狂的想法,会产生影响吗?我的意思是使用同一个 spweb 很长一段时间,也就是说服务器打开的时间......这是一个坏主意吗?而不是每天为每个实例打开关闭 spweb 数千次? spweb 的生存期有限制吗? (这是一个大型共享点应用程序,有很多开发内容)

We have several projects with many DAL. Many sharepoint lists like customers, sells, providers which reflect in C# classes. We make each object implement IDisposable through an abstract mother class. And each time we instantiate an object to get a customer from a list for example, the caller code need to call customer.Dispose() to dispose of the spweb and spsite used to instantiate the object :

 public Customer(int spListItemID):base(LIST_URL)
    {
        try
        {
            spli = Liste.GetItemById(spListItemID);
        }
        catch(ArgumentException)
        {
            spli = null;
        }
    }

and in the constructor base class there is spsite and spweb global variables instantiated and there is the dispose function too.

I was wondering : how about using the same spweb and spsite for the whole sharepoint application ? All our projects know a project that could instantiate those spsite and spweb following a singleton pattern. And we would use this spsite and spweb "forever", we would never close them both and use the same for every object, saving the opening-closing process each time we instantiate an object !

do you think it's a crazy idea, that would have repercussions ? I mean using the same spweb for a very long time, that is to say the time the server is on... is it such a bad idea ? instead of opening closing spweb thousands of time per day for each instantiation ? do spweb have a limited alive period ? (it's a big sharepoint application with lots of development on it)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

亚希 2024-11-22 08:01:12

最大的风险是 SPWeb 可能会过时。在多用户环境中,其他用户可以更改在第一次往返中获取的 SPWeb 属性(例如 - Web 标题),但您仍然保留旧值,因为您没有重新实例化。您可以创建 SPWeb 和 SPSite 的多个实例,只要正确处置它们即可。

The greatest risk is that the SPWeb could turn obsolete. In a multi-user environment the SPWeb properties which are fetched in the first round trip (for example - Web Title) can be changed by another user but you continue to have the old values since you are not instantiating afresh. You can create multiple instances of SPWeb and SPSite as long as you dispose them properly.

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