Home  /  Questions  /  Question



89   96.5
Oct 17, 2010


MVP - Access to Logged in User Object

Hi

I am thinking of applying the MVP pattern to an existing Windows Forms project.  I plan to apply the MVP pattern/structure one form at a time as it will no doubt take a long time to migrate all existing forms to an MVP implementation.

The current structure of my solution/projects is as follows:

 - 'Windows Application' (Presentation Layer)
 - 'Business Logic' class library (Business Layer)
 - 'Business Objects' class library (Business Layer)
 - 'Data Access' class library (Data Layer)

The windows application, business logic and data access projects all reference the business objects project.

In the windows application I store an instance of a 'User' business object (which represents the current logged in user) in a module that is accessible across all forms in the windows application.  Details of the logged in user, mainly the user id, are then passed in to the businss logic layer as necessary in order to log what a user has done e.g. business transactions, etc.

For MVP i will need to create two new projects (class libraries) - one for View interfaces and one for Presenters classes, the windows forms project would then have references to Views, Presenters and Business Objects and the Presenter would have references to Views, Business Objects and Business Logic.  In order for this to work I would still need access to the logged in user in the presenter classes as they will effectively be replacing the code behind the forms.  So the issue I have is - where would I store the instance of the logged in user so that it is accessible by the presenters/presenter project?

One idea I can think of would be to create another project/class library for storing application data such as the logged in user.  This 'application' project would then be referenced by the windows forms application and the presenter class library which would allow for the logged in user object to be accessed by both (I think only temporarily by the windows forms application as eventually only the presenter will need access to the logged in user and control the views/forms accordingly).

Hope the above makes sense and any help would be appreciated.

Thanks

Matt
 1 comment
 
Any suggestions on where to store the logged in user object for a winforms application using MVP? --- Matt Fothergill  Feb 08, 2011



1,364   100.0
Mar 02, 2011
I happen to see this question very late, but in any case MVP is one of my favorite area.  What I have done in my projects in the past is to have a separate class library project for storing states that is required across the apps.

This library will be referenced by the "Presenter".  Your approach seems to be in the same direction.  Make sure you design this class based on the principle of "Depend on abstraction, Don't depend on Implementation" :) so that you can later plugin a different store or replace it with another implementation if need arises.




 1 comment
 
Thanks for the reply Rajesh. A separate class library to store user session state was the option I went with. --- Matt Fothergill  Mar 05, 2011

50   50
Aug 12, 2011
Actually I have question on Matt /Rajiv suggestions.How should the Login Class Library be interacting with Window Form and Presenter.
Is the flow should be  Window form to Login Class Library and then presenter and then result back from presenter to Login Class Library to windows form?
I am new to MVP and I ran into same problem for User Login that Matt had.