diff lib/IMPL/Config/ActivationContext.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents cc2cf8c0edc2
children 7798345304bc
line wrap: on
line diff
--- a/lib/IMPL/Config/ActivationContext.pm	Thu Oct 29 03:50:25 2015 +0300
+++ b/lib/IMPL/Config/ActivationContext.pm	Mon Nov 02 01:56:53 2015 +0300
@@ -5,18 +5,18 @@
 use IMPL::Exception();
 use IMPL::declare {
 	require => {
-		Bag => 'IMPL::Config::ServicesBag',
+		Bag                      => 'IMPL::Config::ServicesBag',
 		ServiceNotFoundException => 'IMPL::Config::ServiceNotFoundException',
 	},
 	base => {
 		'IMPL::Object' => '@_'
 	},
-	props => {
+	props => [
 		container => PROP_RW,
+		instances => PROP_RW,
 		_services => PROP_RW,
-		_cache    => PROP_RW,
 		_stack    => PROP_RW
-	}
+	]
 };
 
 sub CTOR {
@@ -24,8 +24,9 @@
 
 	$this->container($container)
 	  or die IMPL::InvalidArgumentException->new('container');
-	$this->_cache({});
-	$this->_stack([]);
+	$this->_services( $container->services );
+	$this->instances( {} );
+	$this->_stack( [] );
 }
 
 sub EnterScope {
@@ -44,6 +45,7 @@
 			my $container = $this->container;
 			$bag = Bag->new( $this->_services );
 
+			#
 			$bag->Register(
 				$container->GetLinearRoleHash( $_->{role}, $_->{descriptor} ) )
 			  foreach @$services;
@@ -55,46 +57,42 @@
 		$this->_services($bag);
 	}
 
-	push @{$this->_stack}, $info;
+	push @{ $this->_stack }, $info;
 }
 
 sub LeaveScope {
 	my ($this) = @_;
 
-	my $info = pop @{$this->_stack}
+	my $info = pop @{ $this->_stack }
 	  or die IMPL::InvalidOperationException->new();
 
 	$this->_services( $info->{services} ) if $info->{services};
 }
 
-sub GuardScope {
-	my ( $this, $name, $services, $action ) = @_;
-
-	$this->EnterScope( $name, $service );
-	eval { $action ($this) if $action; } my $err = $@;
-	$this->LeaveScope();
-	die $err if $err;
-}
-
 sub Resolve {
 	my ( $this, $role, %opts ) = @_;
-	
-	my $d = $this->_services->Reolve($role);
-	
-	unless($d) {
+
+	my $d = $this->_services->Resolve($role);
+
+	unless ($d) {
 		die ServiceNotFoundException->new($role) unless $opts{optional};
 		return $opts{default};
-	} else {
+	}
+	else {
 		return $d->Activate($this);
 	}
 }
 
 sub Clone {
 	my ($this) = @_;
-	
-	my $clone = SELF->new($this->container);
-	
-	$clone->_
+
+	my $clone = SELF->new( $this->container );
+
+	$clone->_services( $this->_services );
+	$clone->instances( { %{ $this->instances } } );
+	$clone->_stack( [ @{ $this->_stack } ] );
+
+	return $clone;
 }
 
 1;