Hello, I'm in the process of refactoring a large project to use a request-scoped context to pass around information about the "current user". The project is too large to initialize the context everywhere at once.
- Is there a best practice for marking which functions/services/modules have context initialized, and which ones don't?
We have a large number of public APIs and cron jobs, where information about the current user is not available, or only identifiable after some business logic.
-
Is there an ergonomic way to setup custom logic for initializing the request context? The logic in question is generally "Retrieve x entity, check y property, retrieve z entity".
-
For authenticated requests, the context is being initialized in a middleware. For public APIs, does it make more sense to initialize it in the controller or the service?