I have a sharepoint project where we override search box and some other things. We also have a web part page that responds to the search box. All these components should share single configuration. I thought about creating a singleton, but I am not sure how would that ever get cleaned up / removed from the memory / uninstalled.
Any ideas? Any warnings about using singletons in sharepoint? Also, is there a proper way to share an instance of an object between all these componenets?
Edit: I was thinking about a very simple singleton. Configuration only needs to contain 5-20 strings and a dozen integers at most. No complex objects 🙂
As long as the objects being managed by your singleton class are thread-safe there shouldn’t be an issue.
EXAMPLE:
I have a series of object-calls that were taking a long-time to process (7+ seconds). So, I decided to try using a comet-styled long-polling technique to process them. As such, I host a service (as a static singleton) in a single thread and process requests using asynchronous HttpHandler’s…and it works GREAT! And because I’m using the service asynchronously it’s highly efficient because the calling thread gets released immediately (upon completion of processing the service completes the callback).
EDIT:
But your problem of a long processing time still exists, so you still (probably) need an asynchronous solution for the initial fetch. Hows this? Why not COMBINE the asych-solution with custom-caching?
For various (accessibility) reasons, I save my appSetting’s in the database and use a custom-cache for access thereafter.
EXAMPLE of a Custom Cache: