开发者

Where in a domain model is it best to keep a reference to the current user?

开发者 https://www.devze.com 2022-12-19 00:02 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消