Model View Presenter - Global State
When implementing Model View Presenter architecture in a winforms application, where or how should global state be stored? (I am aware global state should be kept to a minimum).
For example, once a user is logged in to the application, where would the custom 'User' object be stored?
Currently I have a public static/shared variable on the Main form which I then access from other forms and pass in to the business logic layer when necessary. The user object also has a property for 'AccessLevel' which is used on other forms to resrtict what users can do.
However with MVP, the main objective is to have the presenter manipulate the view and communicate with the business logic layer. Therefore would it be correct to have a static class within the 'Presenters' dll/assembly with a property for 'LoggedInUser' which would give all 'presenters' access to the user object to allow them to change 'views' as necessary and also allow 'presenters' to pass user details to the business logic layer when needed?
Any other ideas?
For info - Solution Structure:
UI (exe - references Views, Presenters and Business Objects)
Views (dll - containing view interfaces)
Presenters (dll - references Views, Business Objects and Business Logic)
Business Objects (dll)
Business Logic (dll - references Business Objects and Data Access)
Data Access (dll - references Business Objects)
Any help would be appreciated.
Matt Fothergill, Feb 10, 2011
I personally put it in the Model.cs since all my views bind to Presenter.cs in some way.
The "IsUserAllowedAccess" method in Model.cs calls on a static instance of UserSession class. Now it is accessible by all my views and forms.
Robert Blair, Feb 16, 2011