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
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 in SML's documentation, specifically, Section 5: Create a state machine.
In case of CIB, it would allow to pass user's dependencies to created nexus:
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:
struct service : public cib::callback_meta<Payload const &>{};`
struct feature
{
static auto constexpr config = cib::config(
cib::extend<service>(
[](double x, Payload const & p)
{
// do sth with injected x and passed p
}
)
);
};
cib::nexus<nexus_project> nexus{87.0};
In the above service is declared to accept const reference to Payload, but then we'd attempt to declare feature which is attached to a handler which accepts Payloadand a double. Since nexus is instantiated with a double 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
The text was updated successfully, but these errors were encountered:
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.
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/smlSpecifically, 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 in
SML
'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
The text was updated successfully, but these errors were encountered: