php - Laravel Dependency Injection and bindings -
can please clear air me! why need implement interface repository class , bind them in service provider?? what's use of interface if binded specific class?? , if so, why can't inject repository in controller? last thing, dependency anyway? thanks.
the service provider binds service/repository application. should bind either interface (which can used property type dependency injection) or alias (such 'foo.bar').
the disadvantage of using alias dependency must class itself, singleton kept within application. advantage of using contract (interface) that, following ioc pattern, can have registered repository implementing given interface, allowing changes in vendor code, such if change main storage repository replacing service provider, injection still work if singleton registered main interface.
so if intend use vendor (or own code) replace laravel core feature, dependencies injection wil still work, providing vendor repository implements same contract laravel one.
Comments
Post a Comment