Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 parameters? 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?

like image 828
Fikre Avatar asked Sep 05 '25 03:09

Fikre


1 Answers

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.

like image 157
womp Avatar answered Sep 07 '25 23:09

womp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!