diff lib/IMPL/Config/ServiceDescriptor.pm @ 416:cc2cf8c0edc2 ref20150831

sync
author cin
date Thu, 29 Oct 2015 03:50:25 +0300
parents 3d24b10dd0d5
children 3ed0c58e9da3
line wrap: on
line diff
--- a/lib/IMPL/Config/ServiceDescriptor.pm	Tue Oct 20 07:32:55 2015 +0300
+++ b/lib/IMPL/Config/ServiceDescriptor.pm	Thu Oct 29 03:50:25 2015 +0300
@@ -5,7 +5,8 @@
 use IMPL::Exception();
 use IMPL::declare {
 	require => {
-		Bag => 'IMPL::Config::Bag'
+		Bag                 => 'IMPL::Config::Bag',
+		ActivationException => 'IMPL::Config::ActivationException'
 	},
 	base => [
 		'IMPL::Object'             => undef,
@@ -41,30 +42,36 @@
 sub Activate {
 	my ( $this, $context ) = @_;
 
-	$context->EnterScope( $this->_name, $this->services );
+	my $instance;
+	$context->GuardScope(
+		$this->_name,
+		$this->services,
+		sub {
 
-	my $activation = $this->activation;
-	my $cache;
+			my $activation = $this->activation;
+			my $cache;
 
-	if ( $activation == IMPL::Config::Descriptor::ACTIVATE_SINGLETON ) {
-		$cache = $context->container->root->instances;
-	}
-	elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTAINER ) {
-		$cache = $context->container->instances;
-	}
-	elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTEXT ) {
-		$cache = $context->instances;
-	}
+			if ( $activation == IMPL::Config::Descriptor::ACTIVATE_SINGLETON ) {
+				$cache = $context->container->root->instances;
+			}
+			elsif (
+				$activation == IMPL::Config::Descriptor::ACTIVATE_CONTAINER )
+			{
+				$cache = $context->container->instances;
+			}
+			elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTEXT )
+			{
+				$cache = $context->instances;
+			}
 
-	my $instance = $cache->{ ref($this) } if $cache;
+			$instance = $cache->{ ref($this) } if $cache;
+			unless ($instance) {
+				$instance = $this->CreateInstance($context);
+			}
 
-	unless ($instance) {
-		$instance = $this->CreateInstance($context);
-	}
-
-	$cache->{ ref($this) } = $instance if $cache;
-
-	$context->LeaveScope();
+			$cache->{ ref($this) } = $instance if $cache;
+		}
+	);
 
 	return $instance;
 }