3

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)

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
KitAndKat
  • 953
  • 3
  • 14
  • 29

1 Answers1

3

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.

NLV
  • 21,141
  • 40
  • 118
  • 183
  • ok thanks, apart from the title, description and other informations on the website (these are base informations, they will never change for us), is there anything that could change or need to be refreshed or that would inevitably crash because of multi users environment ? they're working on lists, adding, deleting, editing, with event receivers, timer jobs, workflows...:s – KitAndKat Jun 14 '11 at 12:47
  • anyway I guess you're right, there are a lot of properties that would be in conflict, like CurrentUser for example, in that case what would be currentuser ..., the class is so huge and complicated (reflector shows it !), it will inevitably crash being used by several people at the same time, during months... – KitAndKat Jun 14 '11 at 13:51