I have a 开发者_JS百科list of customers shown at a top menu where every customername is a menuitem. Now I want to have the same (same = I do not want to reload my data from database ) customers in another menu.
Both menus are in 2 different UserControls. In every UserControl you can do stuff on that customer-menu. How would you design both menu`s/UserControls/Presenter to get the customerList only one time from database?
I am using winforms MVP pattern.
The complete answer sort of depends on how you get your data from your database and then back to the usercontrol. But since your are using a 'Presenter' I suspect you have a reference to a list of the customers. All you would need to do is pass that reference to each of the two usercontrols and both will have access to exactly the same instance data.
You can load CustomerList in a static list and share this list it's sort of caching mechanism.
I don't know what way you are connecting to your database. If you are just using a DataSource to connect directly to it, I can't help you there.
Otherwise what you could do is put per-request caching in your data access layer so all controls will draw their data from the same cache for the time of the request.
There are many ways in which you can cache your data from the database, this was just one example.
You can connect one time to your database, and store that data locally in a dataset/datatable, you can then pass that around and access it whenever you like.
精彩评论