You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a multitenant application, that isn't using Eloquent, but instead is more of a data mapper style with DB interactions. I have a DB\Tenant class that I register in the container when a tenant is loaded, which can then be injected into classes that I ask the container to build.
The Event Dispatcher keeps a listeners array of string classnames, and resolves them when the event in question is dispatched - so, if I inject a tenant-scoped DB connection in the constructor of a Listener, as far as I understand it, the listener will get rebuilt every time the event is dispatched, with whatever the current tenant DB connection is.
If I make a Subscriber with the same constructor dependency, though, I have a problem. Although the subscriber can be built at the point that the event is dispatched fine, the Dispatcher also has to build it when the application boots in order to access the $subscriber->subscribe() array of Event classnames it should listen to. When I load my login system, I don't know the tenant yet, and so the dependency can't be resolved, and the subscriber can't be registered properly.
At the moment, solutions I have are:
make any constructor dependencies nullable and default to null (feels messy, and bad for static analysis)
use App::make() in the method, or inject a container, and build dependencies when the subscriber is actually called - again, feels messy
make the subscribe() method static and override the Dispatcher to use that instead, so we don't have to build it - sad to have to extend things like that though
I just don't use subscribers for this sort of thing, and manually register the listener against all the events
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a multitenant application, that isn't using Eloquent, but instead is more of a data mapper style with DB interactions. I have a DB\Tenant class that I register in the container when a tenant is loaded, which can then be injected into classes that I ask the container to build.
The Event Dispatcher keeps a listeners array of string classnames, and resolves them when the event in question is dispatched - so, if I inject a tenant-scoped DB connection in the constructor of a Listener, as far as I understand it, the listener will get rebuilt every time the event is dispatched, with whatever the current tenant DB connection is.
If I make a Subscriber with the same constructor dependency, though, I have a problem. Although the subscriber can be built at the point that the event is dispatched fine, the Dispatcher also has to build it when the application boots in order to access the $subscriber->subscribe() array of Event classnames it should listen to. When I load my login system, I don't know the tenant yet, and so the dependency can't be resolved, and the subscriber can't be registered properly.
At the moment, solutions I have are:
Does anybody else have any ideas?
Beta Was this translation helpful? Give feedback.
All reactions