completed NoSugarContainer to match SugarContainer
André Walker [Wed, 3 Aug 2011 23:09:33 +0000 (20:09 -0300)]
t/lib/TestAppCustomContainer/NoSugarContainer.pm

index 2314e50..6abc3d6 100644 (file)
@@ -7,6 +7,34 @@ extends 'Catalyst::IOC::Container';
 
 sub BUILD {
     my $self = shift;
+
+    $self->get_sub_container('component')->add_service(
+        Catalyst::IOC::ConstructorInjection->new(
+            name         => 'model_Bar',
+            class        => 'TestAppCustomContainer::Model::Bar',
+            dependencies => [
+                depends_on( '/application_name' ),
+                depends_on( '/config' ),
+                depends_on( '/model/Foo' ),
+            ],
+        )
+    );
+    $self->get_sub_container('model')->add_service(
+        Catalyst::IOC::BlockInjection->new(
+            name         => 'Bar',
+            dependencies => [
+                depends_on( '/model/Foo' ),
+                depends_on( '/component/model_Bar' ),
+            ],
+            block => sub {
+                my $s        = shift;
+                my $foo      = $s->param('Foo');
+                my $instance = $s->param('model_Bar');
+                return $instance;
+            },
+        )
+    );
+
     $self->get_sub_container('component')->add_service(
         Catalyst::IOC::ConstructorInjection->new(
             name         => 'model_Baz',
@@ -37,6 +65,43 @@ sub BUILD {
             },
         )
     );
+
+    $self->get_sub_container('model')->add_service(
+        Catalyst::IOC::BlockInjection->new(
+            name         => 'Quux',
+
+# FIXME - it should probably be our
+# Catalyst::IOC::LifeCycle::Singleton
+            lifecycle    => 'Singleton',
+            dependencies => [
+                depends_on( '/component/model_Quux' ),
+            ],
+            block => sub { shift->param('model_Bar') },
+        )
+    );
+
+    $self->get_sub_container('component')->add_service(
+        Catalyst::IOC::ConstructorInjection->new(
+            name         => 'model_Fnar',
+            lifecycle    => 'Singleton',
+            class        => 'My::External::Class',
+            dependencies => [
+                depends_on( '/application_name' ),
+                depends_on( '/config' ),
+            ],
+        )
+    );
+    $self->get_sub_container('model')->add_service(
+        Catalyst::IOC::BlockInjection->new(
+            name         => 'model_Fnar',
+            lifecycle    => 'Singleton',
+            dependencies => [
+                depends_on( '/config' ),
+                depends_on( '/component/model_Fnar' ),
+            ],
+            block => sub { shift->param('model_Fnar') },
+        )
+    );
 }
 
 __PACKAGE__->meta->make_immutable;