getting correct name for the component
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
index a9b5dc3..921854c 100644 (file)
@@ -612,18 +612,17 @@ sub get_all_components {
     my $self = shift;
     my %components;
 
+    # FIXME - if we're getting from these containers, we need to either:
+    #   - pass 'ctx' and 'accept_context_args' OR
+    #   - make these params optional
     foreach my $type (qw/model view controller /) {
         my $container = $self->get_sub_container($type);
 
         for my $component ($container->get_service_list) {
-            my $comp = $container->resolve(
-                service => $component
-            );
-            my $comp_name = ref $comp || $comp; # THIS IS WRONG! :)
-                                                # Just as it is called Model::Foo
-                                                # does not mean it has to be
-                                                # an instance of model::foo
-            $components{$comp_name} = $comp;
+            my $comp = $container->get_service($component);
+
+            # is this better?
+            $components{$comp->catalyst_component_name} = $comp->get;
         }
     }
 
@@ -636,8 +635,6 @@ sub add_component {
 
     return unless $type;
 
-    my $component_service_name = "${type}_${name}";
-
     # The 'component' sub-container will create the object, and store it's
     # instance, which, by default, will live throughout the application.
     # The model/view/controller sub-containers only reference the instance
@@ -646,6 +643,12 @@ sub add_component {
     my $instance_container       = $self->get_sub_container('component');
     my $accept_context_container = $self->get_sub_container($type);
 
+    # Custom containers might have added the service already
+    # We don't want to override that
+    return if $accept_context_container->has_service( $name );
+
+    my $component_service_name = "${type}_${name}";
+
     $instance_container->add_service(
         Catalyst::IOC::ConstructorInjection->new(
             name      => $component_service_name,
@@ -656,9 +659,7 @@ sub add_component {
                 depends_on( '/application_name' ),
             ],
         )
-    ) unless $instance_container->has_service( $component_service_name );
-    # ^ custom containers might have added the service already.
-    # we don't want to override that.
+    );
 
     $accept_context_container->add_service(
         Catalyst::IOC::BlockInjection->new(
@@ -668,8 +669,7 @@ sub add_component {
             ],
             block => sub { shift->param($component_service_name) },
         )
-    ) unless $accept_context_container->has_service( $name );
-    # ^ same as above
+    );
 }
 
 # FIXME: should this sub exist?