Comments
[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',
adef3d19 42# t0m - I'm fine with this - sugar can just s/Request/+Catalyst::IOC::LifeCycle::Request/
43# Also, 'Request' is fine as a name for a lifecycle IMO.
b18a77bd 44# FIXME - it should simply be Request (or InstancePerRequest, etc)
45# see Bread/Board/Service.pm line 47
46 lifecycle => '+Catalyst::IOC::LifeCycle::Request',
3ef84846 47 dependencies => [
48 depends_on( '/application_name' ),
49 depends_on( '/config' ),
50 depends_on( '/model/Foo' ),
51 ],
52 )
53 );
54 $self->get_sub_container('model')->add_service(
55 Catalyst::IOC::BlockInjection->new(
56 name => 'Baz',
57 dependencies => [
58 depends_on( '/model/Foo' ),
59 depends_on( '/component/model_Baz' ),
60 ],
61 block => sub {
62 my $s = shift;
63 my $foo = $s->param('Foo');
64 my $instance = $s->param('model_Baz');
65 return $instance;
66 },
67 )
68 );
f831deb1 69
70 $self->get_sub_container('model')->add_service(
71 Catalyst::IOC::BlockInjection->new(
72 name => 'Quux',
73
74# FIXME - it should probably be our
75# Catalyst::IOC::LifeCycle::Singleton
adef3d19 76# t0m - I think normal Singleton is fine here, it's per app lifetime.
f831deb1 77 lifecycle => 'Singleton',
78 dependencies => [
79 depends_on( '/component/model_Quux' ),
80 ],
81 block => sub { shift->param('model_Bar') },
82 )
83 );
84
85 $self->get_sub_container('component')->add_service(
86 Catalyst::IOC::ConstructorInjection->new(
87 name => 'model_Fnar',
88 lifecycle => 'Singleton',
89 class => 'My::External::Class',
90 dependencies => [
91 depends_on( '/application_name' ),
92 depends_on( '/config' ),
93 ],
94 )
95 );
96 $self->get_sub_container('model')->add_service(
97 Catalyst::IOC::BlockInjection->new(
98 name => 'model_Fnar',
99 lifecycle => 'Singleton',
100 dependencies => [
101 depends_on( '/config' ),
102 depends_on( '/component/model_Fnar' ),
103 ],
104 block => sub { shift->param('model_Fnar') },
105 )
106 );
3ef84846 107}
108
88cea23c 109__PACKAGE__->meta->make_immutable;
110
3ef84846 1111;