completed NoSugarContainer to match SugarContainer
[catagits/Catalyst-Runtime.git] / t / lib / TestAppCustomContainer / NoSugarContainer.pm
CommitLineData
88cea23c 1package TestAppCustomContainer::NoSugarContainer;
3ef84846 2use Moose;
88cea23c 3use namespace::autoclean;
4use Catalyst::IOC;
3ef84846 5
6extends 'Catalyst::IOC::Container';
7
8sub BUILD {
9 my $self = shift;
f831deb1 10
11 $self->get_sub_container('component')->add_service(
12 Catalyst::IOC::ConstructorInjection->new(
13 name => 'model_Bar',
14 class => 'TestAppCustomContainer::Model::Bar',
15 dependencies => [
16 depends_on( '/application_name' ),
17 depends_on( '/config' ),
18 depends_on( '/model/Foo' ),
19 ],
20 )
21 );
22 $self->get_sub_container('model')->add_service(
23 Catalyst::IOC::BlockInjection->new(
24 name => 'Bar',
25 dependencies => [
26 depends_on( '/model/Foo' ),
27 depends_on( '/component/model_Bar' ),
28 ],
29 block => sub {
30 my $s = shift;
31 my $foo = $s->param('Foo');
32 my $instance = $s->param('model_Bar');
33 return $instance;
34 },
35 )
36 );
37
3ef84846 38 $self->get_sub_container('component')->add_service(
39 Catalyst::IOC::ConstructorInjection->new(
40 name => 'model_Baz',
88cea23c 41 class => 'TestAppCustomContainer::Model::Baz',
b18a77bd 42
43# FIXME - it should simply be Request (or InstancePerRequest, etc)
44# see Bread/Board/Service.pm line 47
45 lifecycle => '+Catalyst::IOC::LifeCycle::Request',
3ef84846 46 dependencies => [
47 depends_on( '/application_name' ),
48 depends_on( '/config' ),
49 depends_on( '/model/Foo' ),
50 ],
51 )
52 );
53 $self->get_sub_container('model')->add_service(
54 Catalyst::IOC::BlockInjection->new(
55 name => 'Baz',
56 dependencies => [
57 depends_on( '/model/Foo' ),
58 depends_on( '/component/model_Baz' ),
59 ],
60 block => sub {
61 my $s = shift;
62 my $foo = $s->param('Foo');
63 my $instance = $s->param('model_Baz');
64 return $instance;
65 },
66 )
67 );
f831deb1 68
69 $self->get_sub_container('model')->add_service(
70 Catalyst::IOC::BlockInjection->new(
71 name => 'Quux',
72
73# FIXME - it should probably be our
74# Catalyst::IOC::LifeCycle::Singleton
75 lifecycle => 'Singleton',
76 dependencies => [
77 depends_on( '/component/model_Quux' ),
78 ],
79 block => sub { shift->param('model_Bar') },
80 )
81 );
82
83 $self->get_sub_container('component')->add_service(
84 Catalyst::IOC::ConstructorInjection->new(
85 name => 'model_Fnar',
86 lifecycle => 'Singleton',
87 class => 'My::External::Class',
88 dependencies => [
89 depends_on( '/application_name' ),
90 depends_on( '/config' ),
91 ],
92 )
93 );
94 $self->get_sub_container('model')->add_service(
95 Catalyst::IOC::BlockInjection->new(
96 name => 'model_Fnar',
97 lifecycle => 'Singleton',
98 dependencies => [
99 depends_on( '/config' ),
100 depends_on( '/component/model_Fnar' ),
101 ],
102 block => sub { shift->param('model_Fnar') },
103 )
104 );
3ef84846 105}
106
88cea23c 107__PACKAGE__->meta->make_immutable;
108
3ef84846 1091;