jeudi 15 octobre 2020

can service locator decide which service instance to use?

I try to reduce the amount of singleton "manager" classes, i.e. global variables in Unity projects, and in order to decouple "Player" from a concrete "SaveManager", for example. Service locator is not ideal but is the next best thing can be used in Unity that I know of. But if I use a static dictionary with type as the key and instance as the value to implement a service locator, then all classes have to share this same instance. With dependency injection, this can be decided at the composition root which uses which. Can this be achieved with service locator?

Aucun commentaire:

Enregistrer un commentaire