407
|
1 package IMPL::Config::Container;
|
412
|
2 use strict;
|
|
3
|
|
4 use IMPL::lang qw(:base);
|
|
5 use IMPL::declare {
|
|
6 require => {
|
|
7 Descriptor => 'IMPL::Config::Descriptor'
|
|
8 },
|
|
9 base => [
|
|
10 'IMPL::Object' => undef
|
|
11 ],
|
|
12 props => [
|
|
13 roles => 'r',
|
|
14 services => 'r',
|
|
15 instances => 'r'
|
|
16 ]
|
|
17 };
|
|
18
|
|
19 my $nextRoleId = 1;
|
|
20
|
|
21 use IMPL::Exception();
|
|
22
|
|
23 sub Register {
|
|
24 my ($this, $role, $service) = @_;
|
|
25
|
|
26 die IMPL::InvalidArgumentException->new(role => 'The argument is required') unless $role;
|
|
27 die IMPL::InvalidArgumentException->new('service') unless is($service, Descriptor);
|
|
28
|
|
29 if (isarray($role)) {
|
|
30 my $tempRole = "unnamed-" . $nextRoleId++;
|
|
31 $this->role->AddRole($tempRole, $role);
|
|
32 $role = $tempRole;
|
|
33 }
|
|
34
|
|
35 $this->services->Register($role, $service);
|
|
36
|
|
37 }
|
407
|
38
|
|
39 1;
|
|
40
|
|
41 __END__
|
|
42
|
|
43 =pod
|
|
44
|
|
45 =head1 NAME
|
|
46
|
|
47 C<IMPL::Config::Container> - dependency injection container
|
|
48
|
|
49 =head1 SYNOPSIS
|
|
50
|
|
51 =head2 METHODS
|
|
52
|
|
53 =head3 GetService($serviceId)
|
|
54
|
|
55 =over
|
|
56
|
|
57 =item * $serviceId
|
|
58
|
|
59 A string indetifier of the service, it can be in two forms: class name or service name,
|
|
60 for the class name it should be prefixed with C<@>, for example: C<@Foo::Bar>.
|
|
61
|
|
62 =back
|
|
63
|
|
64 The activation container maintains two maps, one for classes and the other for names.
|
|
65 The first one is useful when we searching for an implementation the second one when
|
|
66 we need a particular service.
|
|
67
|
|
68 =head3 RegisterService($descriptor)
|
|
69
|
412
|
70 =cut
|