Commit | Line | Data |
88cea23c |
1 | package TestAppCustomContainer::NoSugarContainer; |
3ef84846 |
2 | use Moose; |
88cea23c |
3 | use namespace::autoclean; |
4 | use Catalyst::IOC; |
3ef84846 |
5 | |
6 | extends 'Catalyst::IOC::Container'; |
7 | |
8 | sub BUILD { |
9 | my $self = shift; |
f831deb1 |
10 | |
11 | $self->get_sub_container('component')->add_service( |
12 | Catalyst::IOC::ConstructorInjection->new( |
13 | name => 'model_Bar', |
fe3f6b6d |
14 | lifecycle => 'Singleton', |
f831deb1 |
15 | class => 'TestAppCustomContainer::Model::Bar', |
16 | dependencies => [ |
17 | depends_on( '/application_name' ), |
18 | depends_on( '/config' ), |
fe3f6b6d |
19 | depends_on( 'model_Foo' ), |
f831deb1 |
20 | ], |
21 | ) |
22 | ); |
23 | $self->get_sub_container('model')->add_service( |
24 | Catalyst::IOC::BlockInjection->new( |
25 | name => 'Bar', |
26 | dependencies => [ |
fe3f6b6d |
27 | Bread::Board::Dependency->new( |
28 | service_path => 'Foo', |
29 | service_params => { |
30 | ctx => +{}, |
31 | accept_context_args => [ +{} ], |
32 | }, |
33 | ), |
f831deb1 |
34 | depends_on( '/component/model_Bar' ), |
35 | ], |
36 | block => sub { |
b463fcad |
37 | my $s = shift; |
38 | |
39 | my $foo = $s->param('Foo'); |
40 | $foo->inc_bar_got_it; |
41 | |
42 | return $s->param('model_Bar'); |
f831deb1 |
43 | }, |
44 | ) |
45 | ); |
46 | |
3ef84846 |
47 | $self->get_sub_container('component')->add_service( |
48 | Catalyst::IOC::ConstructorInjection->new( |
49 | name => 'model_Baz', |
88cea23c |
50 | class => 'TestAppCustomContainer::Model::Baz', |
fe3f6b6d |
51 | lifecycle => 'Singleton', |
52 | #lifecycle => '+Catalyst::IOC::LifeCycle::Request', |
3ef84846 |
53 | dependencies => [ |
54 | depends_on( '/application_name' ), |
55 | depends_on( '/config' ), |
fe3f6b6d |
56 | depends_on( 'model_Foo' ), |
3ef84846 |
57 | ], |
58 | ) |
59 | ); |
60 | $self->get_sub_container('model')->add_service( |
61 | Catalyst::IOC::BlockInjection->new( |
62 | name => 'Baz', |
63 | dependencies => [ |
fe3f6b6d |
64 | Bread::Board::Dependency->new( |
65 | service_path => 'Foo', |
66 | service_params => { |
67 | ctx => +{}, |
68 | accept_context_args => [ +{} ], |
69 | }, |
70 | ), |
3ef84846 |
71 | depends_on( '/component/model_Baz' ), |
72 | ], |
73 | block => sub { |
b463fcad |
74 | my $s = shift; |
75 | |
76 | my $foo = $s->param('Foo'); |
77 | $foo->inc_baz_got_it; |
78 | |
79 | return $s->param('model_Baz'); |
3ef84846 |
80 | }, |
81 | ) |
82 | ); |
f831deb1 |
83 | |
84 | $self->get_sub_container('model')->add_service( |
85 | Catalyst::IOC::BlockInjection->new( |
86 | name => 'Quux', |
f831deb1 |
87 | lifecycle => 'Singleton', |
88 | dependencies => [ |
89 | depends_on( '/component/model_Quux' ), |
90 | ], |
91 | block => sub { shift->param('model_Bar') }, |
92 | ) |
93 | ); |
94 | |
95 | $self->get_sub_container('component')->add_service( |
96 | Catalyst::IOC::ConstructorInjection->new( |
97 | name => 'model_Fnar', |
98 | lifecycle => 'Singleton', |
b463fcad |
99 | class => 'TestAppCustomContainer::External::Class', |
f831deb1 |
100 | dependencies => [ |
101 | depends_on( '/application_name' ), |
102 | depends_on( '/config' ), |
103 | ], |
104 | ) |
105 | ); |
106 | $self->get_sub_container('model')->add_service( |
107 | Catalyst::IOC::BlockInjection->new( |
108 | name => 'model_Fnar', |
109 | lifecycle => 'Singleton', |
110 | dependencies => [ |
111 | depends_on( '/config' ), |
112 | depends_on( '/component/model_Fnar' ), |
113 | ], |
114 | block => sub { shift->param('model_Fnar') }, |
115 | ) |
116 | ); |
3ef84846 |
117 | } |
118 | |
88cea23c |
119 | __PACKAGE__->meta->make_immutable; |
120 | |
3ef84846 |
121 | 1; |