You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application that processes transactions using different processors based on the value of certain attributes in the incoming request. Currently, I defined an interface called Processor and provided implementations for each processor supported in my application. I then register the constructor of each concrete implementation of my Processor interface with a name tag. I would like to get a specific processor from fx using the name tag in my router logic. To handle this today, I defined a processor factory that receives all the processors in a params struct annotated with fx.In and defines a map of processor name to processor implementation and a getProcessor func that takes the processor name and returns the processor if available.
After writing this, I now think it is probably a bad idea to be able to reach into fx and get a specific dependency at least in my use case because this will make fx part of my business logic and tightly couple my application logic with a specific DI tool.
That being said, is there a cleaner and better way to handle what I described above?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have an application that processes transactions using different processors based on the value of certain attributes in the incoming request. Currently, I defined an interface called Processor and provided implementations for each processor supported in my application. I then register the constructor of each concrete implementation of my Processor interface with a name tag. I would like to get a specific processor from fx using the name tag in my router logic. To handle this today, I defined a processor factory that receives all the processors in a params struct annotated with fx.In and defines a map of processor name to processor implementation and a getProcessor func that takes the processor name and returns the processor if available.
After writing this, I now think it is probably a bad idea to be able to reach into fx and get a specific dependency at least in my use case because this will make fx part of my business logic and tightly couple my application logic with a specific DI tool.
That being said, is there a cleaner and better way to handle what I described above?
Beta Was this translation helpful? Give feedback.
All reactions