3 ms·
Well said. Another reason passing dependencies as a parameter is great is to enforce constraints for a functional call. Say you have a database service that po
by jitl 5y ago
Well said.
Another reason passing dependencies as a parameter is great is to enforce constraints for a functional call. Say you have a database service that pools connections to your database. If you want to call some general function
loadPermissionRecords(services, id)
and be sure it only uses one connection for this invocation, you can wrap the database service with a facade that implements your resource constraint when calling it, eg
loadPermissionRecords({ …services, database: database.withConnectionLimit(1) }, id)
Sure, you could add the connection limit as a parameter to loadPermissionRecords, but you’ll also have to pass it down to every other function in the call graph beneath loadPermissionRecords…