Open WojciechMigda opened 2 years ago
This is a fantastic feature suggestion! I've looked at @krzysztof-jusiak's DI library and found that it didn't work in a constexpr context for myself. Maybe there are some changes that could be made.
I would want to be able to inject subclasses of a base interface (virtual function overriding.)
I would also want to inject arbitrary types into template functions.
Thanks for this suggestion @WojciechMigda.
I think that would be nice. I'm happy to experiment and see what can be done.
Hi,
it occured to me yesterday that it would be a nice feature to have stateful nexus, which, in spirit of DI, would then be able to inject extra arguments to handlers registered through features.
What I have in mind is something that Kris Jusiak's library
SML
already has. https://github.com/boost-ext/sml Specifically, in Kris' library state machine instance can be instantiated with extra dependencies. Then, through 'smart' resolution it is able to pass these dependencies to actions which are part of state machine's transitions. Such basic example is presented inSML
's documentation, specifically, Section 5: Create a state machine.In case of
CIB
, it would allow to pass user's dependencies to created nexus:cib::nexus<nexus_project> nexus{Type1: dependency1, Type2: dependency2, ...};
Then,
CIB
when it matches handlers registered against service signature, it would also allow handler's signatures which arguments are superset of those specified in service's definition, extended with types which can be matched against dependencies passed to instantiated nexus. For example:In the above
service
is declared to accept const reference toPayload
, but then we'd attempt to declare feature which is attached to a handler which acceptsPayload
and adouble
. Since nexus is instantiated with adouble
as one of dependencies passed by a user it would allow such feature and pass both arguments - one originating from the point of invocation of the service through the nexus, and the other from the pool of dependencies which are part of nexus' state.I believe this would be huge undertaking to introduce such enhancement, but given that Kris'
SML
library already has it, maybe it could be used as a guidance?Thanks, Wojciech