intel / intel/compile-time-init-build
Dependency injection support
- Dominant language
- C++
- Stars
- 648
- Forks
- 63
- Avg merge
- 4h 25m
- Merged PRs (30d)
- 17
Description
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 in `SML`'s documentation, specifically, [Section 5: _Create a state machine_](https://boost-ext.github.io/sml/tutorial.html).
In case of `CIB`, it would allow to pass user's dependencies to created nexus:
`cib::nexus 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:
struct service : public cib::callback_meta{};`
struct feature
{
static auto constexpr config = cib::config(
cib::extend(
[](double x, Payload const & p)
{
// do sth with injected x and passed p
}
)
);
};
cib::nexus 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 `Payload` _and_ 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
Contributor guide
Assessment
This issue has not been assessed yet.