model Baz
[catagits/Catalyst-Runtime.git] / t / lib / TestAppCustomContainer / NoSugarContainer.pm
index d9f3c68..dc31971 100644 (file)
@@ -7,31 +7,68 @@ extends 'Catalyst::IOC::Container';
 
 sub BUILD {
     my $self = shift;
-    $self->get_sub_container('component')->add_service(
+
+    warn("Add SingletonLifeCycle to model");
+    $self->get_sub_container('model')->add_service(
         Catalyst::IOC::ConstructorInjection->new(
-            name         => 'model_Baz',
+            name             => 'SingletonLifeCycle',
+            lifecycle        => 'Singleton',
+            class            => 'TestAppCustomContainer::Model::SingletonLifeCycle',
+            catalyst_component_name => 'TestAppCustomContainer::Model::SingletonLifeCycle',
+            dependencies     => {
+                application_name => depends_on( '/application_name' ),
+                foo => depends_on('/model/DefaultSetup'),
+            },
+        )
+    );
+
+    $self->get_sub_container('model')->add_service(
+        # FIXME - i think it should be a ConstructorInjection
+        # but only BlockInjection gets ctx parameter
+        Catalyst::IOC::ConstructorInjection->new(
+            name         => 'Baz',
+            lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
             class        => 'TestAppCustomContainer::Model::Baz',
-#            lifecycle    => 'InstancePerContext',
+            dependencies => {
+                application_name => depends_on( '/application_name' ),
+                foo => depends_on('/model/DefaultSetup'),
+            },
+        )
+    );
+
+# 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',
+            lifecycle    => 'Singleton',
+            class        => 'TestAppCustomContainer::External::Class',
             dependencies => [
                 depends_on( '/application_name' ),
-                depends_on( '/config' ),
-                depends_on( '/model/Foo' ),
             ],
+            config => $fnar_config,
         )
     );
     $self->get_sub_container('model')->add_service(
         Catalyst::IOC::BlockInjection->new(
-            name         => 'Baz',
+            name         => 'model_Fnar',
+            lifecycle    => 'Singleton',
             dependencies => [
-                depends_on( '/model/Foo' ),
-                depends_on( '/component/model_Baz' ),
+                depends_on( '/config' ),
+                depends_on( '/component/model_Fnar' ),
             ],
-            block => sub {
-                my $s        = shift;
-                my $foo      = $s->param('Foo');
-                my $instance = $s->param('model_Baz');
-                return $instance;
-            },
+            block => sub { shift->param('model_Fnar') },
         )
     );
 }