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'm not sure if I do understand the question correctly, so if you could elaborate a bit more I will definitely try to answer it more accurately.
Anyway, in your example Command{A, B} and Handler{A, B} are not related at all and, therefore, DI won't be able to create appropriate Commands, but what you can write is following:
struct CommandA {};
struct HandlerA : CommandA {
// HandlerA(some other depenencies...) // additionally Di will take care of creating of all them
}; // new
struct CommandB {};
struct HandlerB : CommandB {}; // new
auto injector = di::make_injector(
di::bind<CommandA>.to<HandlerA> // notice new binding interface with 'to'
, di::bind<CommandB>.to<HandlerB>
);
auto handlerA = injector.create<std::unique_ptr<CommandA>>(); // will give you HandlerA
auto handlerB = injector.create<std::unique_ptr<CommandB>>(); // will give you HandlerB
Hi, Krzysztof!
Can I do something like this:
struct CommandA {};
struct HandlerA {};
struct CommandB {};
struct HandlerB {};
auto injector = di::make_injector(
di::bind<CommandA, HandlerA>
, di::bind<CommandB, HandlerB>
);
auto handler = injector.create();
P.S. You wrote excellent library ;)
The text was updated successfully, but these errors were encountered: