re: Cleaning up your codebase with a clean architecture VIEW POST


Thanks! I don't see where you indicate to use the s3 implementation of the interface, but I imagine that happens typically in laravels service provider? How would you do that if the implementation choice (s3 vs g cloud) had to come from a database value?


That's exactly how I do it, use Laravel's service provider to bind the interface to the implementation.

As to your question, if you needed to choose the implementation based on a config detail (database value in your example), you can do that in the service provider, binding the appropriate implementation choice based on the value.

You could also make an implementation of the interface that chooses which other implementation to use based on the database value, sort of like the proxy pattern, proxying the calls through to the appropriate concrete implementation.


ok, thanks, that makes a lot of sense! I always had trouble thinking through that second part of having configuration come from database values.

code of conduct - report abuse