diff lib/IMPL/Config/Container.pm @ 415:3d24b10dd0d5 ref20150831

working on IMPL::Config::Container
author cin
date Tue, 20 Oct 2015 07:32:55 +0300
parents ec6f2d389d1e
children 3ed0c58e9da3
line wrap: on
line diff
--- a/lib/IMPL/Config/Container.pm	Fri Oct 02 06:56:24 2015 +0300
+++ b/lib/IMPL/Config/Container.pm	Tue Oct 20 07:32:55 2015 +0300
@@ -9,7 +9,8 @@
 		ValueDescriptor   => 'IMPL::Config::ValueDescriptor',
 		ActivationContext => 'IMPL::Config::ActivationContext',
 		Hierarchy         => 'IMPL::Config::Hierarchy',
-		Bag               => 'IMPL::Config::Bag'
+		Bag               => 'IMPL::Config::Bag',
+		Loader            => 'IMPL::Code::Loader'
 	},
 	base => [
 		'IMPL::Object' => undef
@@ -18,36 +19,48 @@
 		roles     => 'r',
 		services  => 'r',
 		instances => 'r',
-		parent    => 'r'
+		parent    => 'r',
+		root      => 'r',
+		loader    => 'r'
 	]
 };
 
 my $nextRoleId = 1;
 
 sub CTOR {
-	my ( $this, $parent ) = @_;
+	my ( $this, $parent, %opts ) = @_;
 
 	$this->instances( {} );
 
+	$this->loader( $opts{loader} || Loader->safe );
+
 	if ($parent) {
 		$this->roles( Hierarchy->new( $parent->roles ) );
 		$this->services( Bag->new( $parent->services ) );
 		$this->parent($parent);
+		$this->root( $parent->root );
 	}
 	else {
 		$this->roles( Hierarchy->new() );
 		$this->services( Bag->new() );
+		$this->root($this);
 	}
 }
 
 sub Register {
 	my ( $this, $role, $service ) = @_;
 
+	die IMPL::InvalidArgumentException->new('service')
+	  unless is( $service, Descriptor );
+	$this->services->Register( $this->GetLinearRoleHash($role), $service );
+}
+
+sub GetLinearRoleHash {
+	my ( $this, $role ) = @_;
+
 	die IMPL::InvalidArgumentException->new(
 		role => 'The argument is required' )
 	  unless $role;
-	die IMPL::InvalidArgumentException->new('service')
-	  unless is( $service, Descriptor );
 
 	if ( isarray($role) ) {
 		my $tempRole = "unnamed-" . $nextRoleId++;
@@ -55,10 +68,7 @@
 		$role = $tempRole;
 	}
 
-	$service = ValueDescriptor->new( value => $service )
-	  unless is( $service, Descriptor );
-
-	$this->services->Register( $this->roles->GetLinearRoleHash($role), $service );
+	$this->roles->GetLinearRoleHash($role);
 }
 
 sub Resolve {
@@ -105,21 +115,10 @@
 
 =head2 METHODS
 
-=head3 GetService($serviceId)
-
-=over
-
-=item * $serviceId
+=head3 Resolve($role)
 
-A string indetifier of the service, it can be in two forms: class name or service name,
-for the class name it should be prefixed with C<@>, for example: C<@Foo::Bar>.
-
-=back
+=head3 ResolveAll($role, shared => $useSharedContext)
 
-The activation container maintains two maps, one for classes and the other for names.
-The first one is useful when we searching for an implementation the second one when
-we need a particular service. 
-
-=head3 RegisterService($descriptor)
+=head3 Register($role, $service)
 
 =cut