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 | |
ced6f9e2 |
11 | $self->get_sub_container('model')->add_service( |
12 | Catalyst::IOC::ConstructorInjection->new( |
13 | name => 'Bar', |
a0475a83 |
14 | lifecycle => 'Singleton', |
15 | class => 'TestAppCustomContainer::Model::Bar', |
a0475a83 |
16 | dependencies => { |
17 | application_name => depends_on( '/application_name' ), |
18 | config => depends_on( '/config' ), |
ced6f9e2 |
19 | foo => depends_on('/model/Foo'), |
f831deb1 |
20 | }, |
21 | ) |
22 | ); |
23 | |
3ef84846 |
24 | $self->get_sub_container('model')->add_service( |
a0475a83 |
25 | # FIXME - i think it should be a ConstructorInjection |
26 | # but only BlockInjection gets ctx parameter |
3ef84846 |
27 | Catalyst::IOC::BlockInjection->new( |
28 | name => 'Baz', |
a0475a83 |
29 | lifecycle => '+Catalyst::IOC::LifeCycle::Request', |
3ef84846 |
30 | dependencies => [ |
fe3f6b6d |
31 | Bread::Board::Dependency->new( |
a0475a83 |
32 | service_name => 'foo', |
fe3f6b6d |
33 | service_path => 'Foo', |
c736869e |
34 | |
35 | # FIXME - same as above |
fe3f6b6d |
36 | service_params => { |
37 | ctx => +{}, |
38 | accept_context_args => [ +{} ], |
39 | }, |
40 | ), |
3ef84846 |
41 | ], |
42 | block => sub { |
a0475a83 |
43 | TestAppCustomContainer::Model::Baz->new(foo => shift->param('foo')); |
3ef84846 |
44 | }, |
45 | ) |
46 | ); |
f831deb1 |
47 | |
48 | $self->get_sub_container('model')->add_service( |
49 | Catalyst::IOC::BlockInjection->new( |
50 | name => 'Quux', |
f831deb1 |
51 | lifecycle => 'Singleton', |
52 | dependencies => [ |
53 | depends_on( '/component/model_Quux' ), |
54 | ], |
55 | block => sub { shift->param('model_Bar') }, |
56 | ) |
57 | ); |
58 | |
59 | $self->get_sub_container('component')->add_service( |
60 | Catalyst::IOC::ConstructorInjection->new( |
61 | name => 'model_Fnar', |
62 | lifecycle => 'Singleton', |
b463fcad |
63 | class => 'TestAppCustomContainer::External::Class', |
f831deb1 |
64 | dependencies => [ |
65 | depends_on( '/application_name' ), |
66 | depends_on( '/config' ), |
67 | ], |
68 | ) |
69 | ); |
70 | $self->get_sub_container('model')->add_service( |
71 | Catalyst::IOC::BlockInjection->new( |
72 | name => 'model_Fnar', |
73 | lifecycle => 'Singleton', |
74 | dependencies => [ |
75 | depends_on( '/config' ), |
76 | depends_on( '/component/model_Fnar' ), |
77 | ], |
78 | block => sub { shift->param('model_Fnar') }, |
79 | ) |
80 | ); |
3ef84846 |
81 | } |
82 | |
88cea23c |
83 | __PACKAGE__->meta->make_immutable; |
84 | |
3ef84846 |
85 | 1; |