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)

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top