Answer the question
In order to leave comments, you need to log in
Based on your experience, how critical is it to pass configs to the class constructor?
Suppose there is a RedisCache class, it needs to know where to connect, looked at different frameworks, in one config it looks for the caching class itself from the global config, in another they are passed directly to the constructor, in the third the Connection object is passed.
Which method is more rational based on your experience?
Answer the question
In order to leave comments, you need to log in
From experience, it's best to use DI (Dependency Injection).
that is, there is a config where the redis parameters for the cache are specified.
and there is a DI config where it is indicated how to create Redis and RedisCache objects. most likely a Redis object will be passed to the RedisCache constructor.
Although in the case of DI, you can painlessly convert any option into any other at any stage of development.
and also, for example, at some point you will have one radish instance for all purposes for the entire project (and you don’t need to make copies of the Redis object, with separate connections), but you can easily redo it only through the config and allocate a separate cache instance to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question