I have 3 user controls, each one of which will need to pull data from an XML feed based on various URL parameters and such. Now the data in this XML feed will be identical for all 3 user controls, because they're all sending the same request.
It seems silly to make 3 separate requests for what will be identical data.
My idea is to have a singleton that I'll call which will do one request to the XML service and then present nicely parsed results to the user controls.
i.e.:
- User control A grabs the singleton.
- User control A asks the singleton to make a request...
- Singleton makes the request and parses the XML into various properties.
- User control C grabs the singleton and pulls its data out.
- User control A pulls its data out of the singleton.
- User control B grabs the singleton and pulls its data out.
Now that I think about it, I'll need to add some sort of blocking to the "make a request" method so that I'm not calling it multiple times concurrently — I'm fairly new to C#, what's the easiest way to do this? Do user controls even run concurrently? Is there a nice overview for this somewhere?
The question is "will a singleton be reinstantiated in between page requests in C#?", but I guess a more general question would be "am I doing a silly thing", "what's the nicest way to do this?" or "is there an easier way to do what I want?".