-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injection vs facades vs helpers? #29
Comments
a) Constructor injection: |
I personally use those depending on context: In libraries
In application code
|
I think constructor or method injections lead to code that is easier to test. Having a facade or global helper within the class itself leads to tightly coupled code. Making it harder to test, refactor, etc. (doesn't mean impossible, but harder). |
@alexkuc Also if you are using the new Octane/Swoole system instead of php-fpm, So in current version its best to use Facades everywhere, unless you need support for non-laravel projects. |
Facades must die. If you use facades (e.g. Remember, Unit test must extend |
I wouldn't go this harsh. I believe helpers and facades in Laravel were made for RAD and POC code. When you have clear business and technical requirements, it must makes sense to spend time writer leaner and cleaner code. But when you are improvising or dealing with high level of uncertainty, I think that would lead to waste. Imho. |
I was just wondering what the best practices are or what the community's thoughts are on when to use:
a) Constructor injection
b) Method injection
c) Facades
d) Global helper functions
The text was updated successfully, but these errors were encountered: