In web applications user login information is usually stored in a session but how about windows applications? Is using a singleton the right thing to do? Should I just use a static property?
Lets say that I store the login information in a static property ApplicationController. LoggedInUser. When a user logs in successfully, that property is set. Before a successful login, LoggedInUser returns null. Then when calling for an example OrdersService from my OrderListPresenter-class, I use the LoggedInUser as a parameter.
var service = new OrdersService();
var orderCollection = service.GetOrdersByUserID(
ApplicationController.LoggedInUser.ID);
Ok, this works but it also makes writing the unit tests somewhat harder. I don't like working with singletons / static members from my unit tests.
Maybe I could inject the ApplicationController to every class which needs to access logged in user? Any other ideas?
What do you think is the best way to handle this?