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