more comments
[catagits/Catalyst-Runtime.git] / t / lib / TestAppCustomContainer / NoSugarContainer.pm
index e65f1c9..09e99dc 100644 (file)
@@ -8,99 +8,57 @@ extends 'Catalyst::IOC::Container';
 sub BUILD {
     my $self = shift;
 
-    $self->get_sub_container('component')->add_service(
-        Catalyst::IOC::ConstructorInjection->new(
-            name         => 'model_Bar',
-            lifecycle    => 'Singleton',
-            class        => 'TestAppCustomContainer::Model::Bar',
-            dependencies => [
-                depends_on( '/application_name' ),
-                depends_on( '/config' ),
-                depends_on( '/model/Foo' ),
-            ],
-        )
-    );
+    warn("Add Bar to model");
     $self->get_sub_container('model')->add_service(
-        Catalyst::IOC::BlockInjection->new(
-            name         => 'Bar',
-            lifecycle    => 'Singleton',
-            dependencies => [
-                Bread::Board::Dependency->new(
-                    service_path => 'Foo',
-
-                    # FIXME - obviously this is a mistake
-                    # what to do with ctx here?
-                    # I have no way to get $s here, do I?
-                    service_params => {
-                        ctx => +{},
-                        accept_context_args => [ +{} ],
-                    },
-                ),
-                depends_on( '/component/model_Bar' ),
-            ],
-            block => sub {
-                my $s   = shift;
-
-                my $foo = $s->param('Foo');
-                $foo->inc_bar_got_it;
-
-                return $s->param('model_Bar');
-            },
-        )
-    );
-
-    $self->get_sub_container('component')->add_service(
         Catalyst::IOC::ConstructorInjection->new(
-            name         => 'model_Baz',
-            class        => 'TestAppCustomContainer::Model::Baz',
-            lifecycle    => 'Singleton',
-
-            # while it doesn't fully work
-            #lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
-            dependencies => [
-                depends_on( '/application_name' ),
-                depends_on( '/config' ),
-                depends_on( '/model/Foo' ),
-            ],
-        )
-    );
-    $self->get_sub_container('model')->add_service(
-        Catalyst::IOC::BlockInjection->new(
-            name         => 'Baz',
-            dependencies => [
-                Bread::Board::Dependency->new(
-                    service_path => 'Foo',
-
-                    # FIXME - same as above
-                    service_params => {
-                        ctx => +{},
-                        accept_context_args => [ +{} ],
-                    },
-                ),
-                depends_on( '/component/model_Baz' ),
-            ],
-            block => sub {
-                my $s   = shift;
-
-                my $foo = $s->param('Foo');
-                $foo->inc_baz_got_it;
-
-                return $s->param('model_Baz');
+            name             => 'Bar',
+            lifecycle        => 'Singleton',
+            class            => 'TestAppCustomContainer::Model::Bar',
+            catalyst_component_name => 'TestAppCustomContainer::Model::Bar',
+            dependencies     => {
+                application_name => depends_on( '/application_name' ),
+                foo => depends_on('/model/DefaultSetup'),
             },
         )
     );
 
-    $self->get_sub_container('model')->add_service(
-        Catalyst::IOC::BlockInjection->new(
-            name         => 'Quux',
-            lifecycle    => 'Singleton',
-            dependencies => [
-                depends_on( '/component/model_Quux' ),
-            ],
-            block => sub { shift->param('model_Bar') },
-        )
-    );
+#    $self->get_sub_container('model')->add_service(
+#        # FIXME - i think it should be a ConstructorInjection
+#        # but only BlockInjection gets ctx parameter
+#        Catalyst::IOC::BlockInjection->new(
+#            name         => 'Baz',
+#            lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
+#            dependencies => [
+#                Bread::Board::Dependency->new(
+#                    service_name => 'foo',
+#                    service_path => 'Foo',
+#
+#                    # FIXME - same as above
+#                    service_params => {
+#                        ctx => +{},
+#                        accept_context_args => [ +{} ],
+#                    },
+#                ),
+#            ],
+#            block => sub {
+#                TestAppCustomContainer::Model::Baz->new(foo => shift->param('foo'));
+#            },
+#        )
+#    );
 
+# Broken deps!?!
+#    $self->get_sub_container('model')->add_service(
+#        Catalyst::IOC::BlockInjection->new(
+#            name         => 'Quux',
+#            lifecycle    => 'Singleton',
+#            dependencies => [
+#                depends_on( '/component/model_Quux' ),
+#            ],
+#            block => sub { shift->param('model_Bar') },
+#        )
+#    );
+
+    my $fnar_config = $self->resolve(service => 'config')->{'Model::Fnar'} || {};
     $self->get_sub_container('component')->add_service(
         Catalyst::IOC::ConstructorInjection->new(
             name         => 'model_Fnar',
@@ -108,8 +66,8 @@ sub BUILD {
             class        => 'TestAppCustomContainer::External::Class',
             dependencies => [
                 depends_on( '/application_name' ),
-                depends_on( '/config' ),
             ],
+            config => $fnar_config,
         )
     );
     $self->get_sub_container('model')->add_service(