Answer the question
In order to leave comments, you need to log in
What is Autowiring in DI Containers?
I began to study the structure of DI containers in general and in particular for C ++. After reviewing a number of implementations, I chose Hypodermic for myself. In general, using Unit tests, I figured out how to work with the library, but I didn’t quite understand about Autowiring. What it is?
PS I am attaching the text of two Unit-tests with the problem in question.
BOOST_AUTO_TEST_CASE(autowired_registration_follows_the_usual_registration_rules)
{
// Arrange
ContainerBuilder c;
// Act
c.autowireType< ServiceA >().as< IServiceA >();
c.autowireType< ServiceB >().singleInstance();
// Assert
auto container = c.build();
auto serviceB = container->resolve< ServiceB >();
auto nullServiceB = container->resolve< IServiceB >();
BOOST_CHECK(serviceB != nullptr);
BOOST_CHECK(nullServiceB == nullptr);
BOOST_CHECK(serviceB == container->resolve< ServiceB >());
}
BOOST_AUTO_TEST_CASE(autowired_registration_can_resolve_all_services)
{
// Arrange
ContainerBuilder c;
c.autowireType< ServiceA >().as< IServiceA >().as< IRunWithScissors >();
c.autowireType< ServiceB >().as< IServiceB >();
c.autowireType< ServiceRunningWithScissors >().as< IServiceB >();
c.autowireType< ServiceBController >();
auto container = c.build();
// Act
auto serviceBController = container->resolve< ServiceBController >();
// Assert
BOOST_CHECK(serviceBController != nullptr);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question