Where in a domain model is it best to keep a reference to the current user?
How should the current user be passed to the repository classes?
The current user's credentials are needed for the connection string used by the repositories. Should each repository be instantiated by having the username and password passed as constructor parame开发者_开发百科ters? That would mean that each domain object having a repository should be aware of the current user.
Where in my domain model is it best to keep a reference to the current user?
Given your description, I would tend to scope the current user to some sort of "ApplicationContext" object. This would be analogous to HttpContext/Session for ASP.Net or some kind of Singleton instance in a forms application.
精彩评论