08bd91661b8b322897f9491f441575c04c4aff2d
[catagits/Catalyst-Runtime.git] / t / lib / TestAppCustomContainer / NoSugarContainer.pm
1 package TestAppCustomContainer::NoSugarContainer;
2 use Moose;
3 use namespace::autoclean;
4 use Catalyst::IOC;
5
6 extends 'Catalyst::IOC::Container';
7
8 sub BUILD {
9     my $self = shift;
10
11     warn("Add Bar to model");
12     my $bar_config = $self->resolve(service => 'config')->{'Model::Bar'} || {};
13     $self->get_sub_container('model')->add_service(
14         Catalyst::IOC::ConstructorInjection->new(
15             name             => 'Bar',
16             lifecycle        => 'Singleton',
17             class            => 'TestAppCustomContainer::Model::Bar',
18             config           => $bar_config,
19             dependencies     => {
20                 application_name => depends_on( '/application_name' ),
21                 config => depends_on( '/config' ),
22                 foo => depends_on('/model/DefaultSetup'),
23             },
24         )
25     );
26
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 #    );
50
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 #    );
62
63     my $fnar_config = $self->resolve(service => 'config')->{'Model::Fnar'} || {};
64     $self->get_sub_container('component')->add_service(
65         Catalyst::IOC::ConstructorInjection->new(
66             name         => 'model_Fnar',
67             lifecycle    => 'Singleton',
68             class        => 'TestAppCustomContainer::External::Class',
69             dependencies => [
70                 depends_on( '/application_name' ),
71             ],
72             config => $fnar_config,
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     );
86 }
87
88 __PACKAGE__->meta->make_immutable;
89
90 1;