ConstructorInjection now depends on the application, not the application_name
André Walker [Wed, 2 May 2012 02:03:55 +0000 (23:03 -0300)]
lib/Catalyst/IOC/ConstructorInjection.pm
lib/Catalyst/IOC/Container.pm

index bed9355..392d2b7 100644 (file)
@@ -44,12 +44,7 @@ sub get {
     my %config = (%{ $self->config || {} }, %{ $params });
     $self->_clear_config;
 
-    # FIXME - Is depending on the application name to pass into constructors here a good idea?
-    #         This makes app/ctx split harder I think.. Need to think more here, but I think
-    #         we want to pass the application in as a parameter when building the service
-    #         rather than depending on the app name, so that later, when the app becomes an instance
-    #         then it'll get passed in, and components can stash themselves 'per app instance'
-    my $app_name    = $self->param('application_name');
+    my $app_name = $self->param('application');
 
     # Stash catalyst_component_name in the config here, so that custom COMPONENT
     # methods also pass it.
index 22f29b8..e5609b3 100644 (file)
@@ -41,6 +41,13 @@ has substitutions => (
     default => sub { +{} },
 );
 
+has application => (
+    is       => 'ro',
+    isa      => 'Catalyst|Str',
+    lazy     => 1,
+    default  => sub { shift->application_name },
+);
+
 has application_name => (
     is       => 'ro',
     isa      => 'Str',
@@ -66,6 +73,7 @@ sub BUILD {
         substitutions
         file
         driver
+        application
         application_name
         prefix
         extensions
@@ -189,6 +197,15 @@ sub build_root_service {
     );
 }
 
+sub build_application_service {
+    my $self = shift;
+
+    return Bread::Board::Literal->new(
+        name  => 'application',
+        value => $self->application,
+    );
+}
+
 sub build_application_name_service {
     my $self = shift;
 
@@ -719,7 +736,7 @@ sub add_component {
             class     => $component,
             lifecycle => 'Singleton',
             dependencies => [
-                depends_on( '/application_name' ),
+                depends_on( '/application' ),
             ],
         ),
     );