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( |
a0475a83 |
12 | # Catalyst::IOC::ConstructorInjection gives the constructor the wrong |
13 | # parameters |
14 | Bread::Board::ConstructorInjection->new( |
15 | name => 'model_Bar', |
16 | lifecycle => 'Singleton', |
17 | class => 'TestAppCustomContainer::Model::Bar', |
18 | constructor_name => 'new', |
19 | dependencies => { |
20 | application_name => depends_on( '/application_name' ), |
21 | config => depends_on( '/config' ), |
22 | foo => Bread::Board::Dependency->new( |
23 | service_name => 'foo', |
24 | service_path => '/model/Foo', |
c736869e |
25 | |
26 | # FIXME - obviously this is a mistake |
27 | # what to do with ctx here? |
28 | # I have no way to get $s here, do I? |
fe3f6b6d |
29 | service_params => { |
30 | ctx => +{}, |
31 | accept_context_args => [ +{} ], |
32 | }, |
33 | ), |
a0475a83 |
34 | }, |
35 | ) |
36 | ); |
37 | $self->get_sub_container('model')->add_service( |
38 | Catalyst::IOC::BlockInjection->new( |
39 | name => 'Bar', |
40 | lifecycle => 'Singleton', |
41 | dependencies => [ |
f831deb1 |
42 | depends_on( '/component/model_Bar' ), |
43 | ], |
44 | block => sub { |
a0475a83 |
45 | shift->param('model_Bar'); |
f831deb1 |
46 | }, |
47 | ) |
48 | ); |
49 | |
a0475a83 |
50 | # FIXME - this is to avoid the default service to be added |
51 | # if that happened, the app would die |
3ef84846 |
52 | $self->get_sub_container('component')->add_service( |
a0475a83 |
53 | service model_Baz => 'TestAppCustomContainer::Model::Baz', |
3ef84846 |
54 | ); |
55 | $self->get_sub_container('model')->add_service( |
a0475a83 |
56 | # FIXME - i think it should be a ConstructorInjection |
57 | # but only BlockInjection gets ctx parameter |
3ef84846 |
58 | Catalyst::IOC::BlockInjection->new( |
59 | name => 'Baz', |
a0475a83 |
60 | lifecycle => '+Catalyst::IOC::LifeCycle::Request', |
3ef84846 |
61 | dependencies => [ |
fe3f6b6d |
62 | Bread::Board::Dependency->new( |
a0475a83 |
63 | service_name => 'foo', |
fe3f6b6d |
64 | service_path => 'Foo', |
c736869e |
65 | |
66 | # FIXME - same as above |
fe3f6b6d |
67 | service_params => { |
68 | ctx => +{}, |
69 | accept_context_args => [ +{} ], |
70 | }, |
71 | ), |
3ef84846 |
72 | ], |
73 | block => sub { |
a0475a83 |
74 | TestAppCustomContainer::Model::Baz->new(foo => shift->param('foo')); |
3ef84846 |
75 | }, |
76 | ) |
77 | ); |
f831deb1 |
78 | |
79 | $self->get_sub_container('model')->add_service( |
80 | Catalyst::IOC::BlockInjection->new( |
81 | name => 'Quux', |
f831deb1 |
82 | lifecycle => 'Singleton', |
83 | dependencies => [ |
84 | depends_on( '/component/model_Quux' ), |
85 | ], |
86 | block => sub { shift->param('model_Bar') }, |
87 | ) |
88 | ); |
89 | |
90 | $self->get_sub_container('component')->add_service( |
91 | Catalyst::IOC::ConstructorInjection->new( |
92 | name => 'model_Fnar', |
93 | lifecycle => 'Singleton', |
b463fcad |
94 | class => 'TestAppCustomContainer::External::Class', |
f831deb1 |
95 | dependencies => [ |
96 | depends_on( '/application_name' ), |
97 | depends_on( '/config' ), |
98 | ], |
99 | ) |
100 | ); |
101 | $self->get_sub_container('model')->add_service( |
102 | Catalyst::IOC::BlockInjection->new( |
103 | name => 'model_Fnar', |
104 | lifecycle => 'Singleton', |
105 | dependencies => [ |
106 | depends_on( '/config' ), |
107 | depends_on( '/component/model_Fnar' ), |
108 | ], |
109 | block => sub { shift->param('model_Fnar') }, |
110 | ) |
111 | ); |
3ef84846 |
112 | } |
113 | |
88cea23c |
114 | __PACKAGE__->meta->make_immutable; |
115 | |
3ef84846 |
116 | 1; |