diff lib/IMPL/Config/Container.pm @ 412:30e8c6a74937 ref20150831

working on di container (role based registrations)
author cin
date Mon, 21 Sep 2015 19:54:10 +0300
parents c6e90e02dd17
children af8d359ee4cc
line wrap: on
line diff
--- a/lib/IMPL/Config/Container.pm	Mon Sep 21 00:53:10 2015 +0300
+++ b/lib/IMPL/Config/Container.pm	Mon Sep 21 19:54:10 2015 +0300
@@ -1,4 +1,40 @@
 package IMPL::Config::Container;
+use strict;
+
+use IMPL::lang qw(:base);
+use IMPL::declare {
+	require => {
+		Descriptor => 'IMPL::Config::Descriptor'
+	},
+	base => [
+		'IMPL::Object' => undef
+	],
+	props => [
+		roles => 'r',
+		services => 'r',
+		instances => 'r'
+	]
+};
+
+my $nextRoleId = 1;
+
+use IMPL::Exception();
+
+sub Register {
+	my ($this, $role, $service) = @_;
+	
+	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++;
+        $this->role->AddRole($tempRole, $role);
+        $role = $tempRole;
+	}
+	
+	$this->services->Register($role, $service);
+	
+}
 
 1;
 
@@ -31,4 +67,4 @@
 
 =head3 RegisterService($descriptor)
 
-=cut
\ No newline at end of file
+=cut