Implementing multiple services with shared and unique methods using Effect Typescript library
Hi there! I'm wrapping my head around how to find a good way to implement a multitude of services that all share a common interface but also provide additional properties / methods when being used directly. It's kinda like having
When I use those services in a certain part of my program, I just want to call
This is quite easy when using a shared interface for regular classes or when using
Do you have any suggestions for how to implement this properly? And ideally also an example how I can dynamically get a service from the current context based on the service class only? I tried several options but I'm not super happy with them and have the feeling that I just can't see the forest for the trees...
thanks a lot!
ServiceA, ServiceB and ServiceC and all of them are able to say hello() but ServiceB also has an additional method bark() When I use those services in a certain part of my program, I just want to call
hello() based on an id/tag that I want to use to pick the corresponding service from my context. This is quite easy when using a shared interface for regular classes or when using
Context.Tag . But I can't get the former to work with Effect.Service unless I specify the whole return type upfront and therefore lose any type inference, and the latter limits the implementation to exactly what's being defined by the Tag. Do you have any suggestions for how to implement this properly? And ideally also an example how I can dynamically get a service from the current context based on the service class only? I tried several options but I'm not super happy with them and have the feeling that I just can't see the forest for the trees...
