forked from rasmus-storjohann/Inject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
57 lines (47 loc) · 1.02 KB
/
Main.cpp
File metadata and controls
57 lines (47 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Configurator.hpp"
#include <iostream>
struct Service1;
struct Service2;
struct Service3;
struct Service1
{
Service1(Service2*, Service3*)
{
std::cout << "Service1" << std::endl;
}
};
std::unique_ptr<Service1> Service1Factory(Service3* s3, Service2* s2)
{
return std::unique_ptr<Service1>(new Service1(s2, s3));
}
struct Service2
{
Service2(const Service3*)
{
std::cout << "Service2" << std::endl;
}
};
std::unique_ptr<Service2> Service2Factory(const Service3* s3)
{
return std::unique_ptr<Service2>(new Service2(s3));
}
struct Service3
{
Service3()
{
std::cout << "Service3" << std::endl;
}
};
std::unique_ptr<Service3> Service3Factory()
{
return std::unique_ptr<Service3>(new Service3());
}
int main(int, char**)
{
Injection::Configurator cfg;
cfg.AddFactory(Service1Factory);
cfg.AddFactory(Service2Factory);
cfg.AddFactory(Service3Factory);
auto injector = cfg.CreateInjector();
Service1* svc = injector.Get<Service1>();
}