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', |
c736869e |
29 | |
30 | # FIXME - obviously this is a mistake |
31 | # what to do with ctx here? |
32 | # I have no way to get $s here, do I? |
fe3f6b6d |
33 | service_params => { |
34 | ctx => +{}, |
35 | accept_context_args => [ +{} ], |
36 | }, |
37 | ), |
f831deb1 |
38 | depends_on( '/component/model_Bar' ), |
39 | ], |
40 | block => sub { |
b463fcad |
41 | my $s = shift; |
42 | |
43 | my $foo = $s->param('Foo'); |
44 | $foo->inc_bar_got_it; |
45 | |
46 | return $s->param('model_Bar'); |
f831deb1 |
47 | }, |
48 | ) |
49 | ); |
50 | |
3ef84846 |
51 | $self->get_sub_container('component')->add_service( |
52 | Catalyst::IOC::ConstructorInjection->new( |
53 | name => 'model_Baz', |
88cea23c |
54 | class => 'TestAppCustomContainer::Model::Baz', |
fe3f6b6d |
55 | lifecycle => 'Singleton', |
c736869e |
56 | |
57 | # while it doesn't fully work |
fe3f6b6d |
58 | #lifecycle => '+Catalyst::IOC::LifeCycle::Request', |
3ef84846 |
59 | dependencies => [ |
60 | depends_on( '/application_name' ), |
61 | depends_on( '/config' ), |
fe3f6b6d |
62 | depends_on( 'model_Foo' ), |
3ef84846 |
63 | ], |
64 | ) |
65 | ); |
66 | $self->get_sub_container('model')->add_service( |
67 | Catalyst::IOC::BlockInjection->new( |
68 | name => 'Baz', |
69 | dependencies => [ |
fe3f6b6d |
70 | Bread::Board::Dependency->new( |
71 | service_path => 'Foo', |
c736869e |
72 | |
73 | # FIXME - same as above |
fe3f6b6d |
74 | service_params => { |
75 | ctx => +{}, |
76 | accept_context_args => [ +{} ], |
77 | }, |
78 | ), |
3ef84846 |
79 | depends_on( '/component/model_Baz' ), |
80 | ], |
81 | block => sub { |
b463fcad |
82 | my $s = shift; |
83 | |
84 | my $foo = $s->param('Foo'); |
85 | $foo->inc_baz_got_it; |
86 | |
87 | return $s->param('model_Baz'); |
3ef84846 |
88 | }, |
89 | ) |
90 | ); |
f831deb1 |
91 | |
92 | $self->get_sub_container('model')->add_service( |
93 | Catalyst::IOC::BlockInjection->new( |
94 | name => 'Quux', |
f831deb1 |
95 | lifecycle => 'Singleton', |
96 | dependencies => [ |
97 | depends_on( '/component/model_Quux' ), |
98 | ], |
99 | block => sub { shift->param('model_Bar') }, |
100 | ) |
101 | ); |
102 | |
103 | $self->get_sub_container('component')->add_service( |
104 | Catalyst::IOC::ConstructorInjection->new( |
105 | name => 'model_Fnar', |
106 | lifecycle => 'Singleton', |
b463fcad |
107 | class => 'TestAppCustomContainer::External::Class', |
f831deb1 |
108 | dependencies => [ |
109 | depends_on( '/application_name' ), |
110 | depends_on( '/config' ), |
111 | ], |
112 | ) |
113 | ); |
114 | $self->get_sub_container('model')->add_service( |
115 | Catalyst::IOC::BlockInjection->new( |
116 | name => 'model_Fnar', |
117 | lifecycle => 'Singleton', |
118 | dependencies => [ |
119 | depends_on( '/config' ), |
120 | depends_on( '/component/model_Fnar' ), |
121 | ], |
122 | block => sub { shift->param('model_Fnar') }, |
123 | ) |
124 | ); |
3ef84846 |
125 | } |
126 | |
88cea23c |
127 | __PACKAGE__->meta->make_immutable; |
128 | |
3ef84846 |
129 | 1; |