jasonmay/perl6-ioc/lib/IoC/Container

perl6-ioc src

NAME

IoC::Container

SYNOPSIS

my $c = IoC::Container.new();
  $c.add-service(
      'logfile', IoC::Literal.new(
          :lifecycle('Singleton'),
          :value('logfile.txt'),
      )
  );

  $c.add-service(
      'logger', IoC::ConstructorInjection.new(
          :class('Foo'),
          :lifecycle('Singleton'),
          :dependencies({
              'logfile' => 'logfile',
          }),
      )
  );

  $c.add-service(
      'storage', IoC::BlockInjection.new(
          :lifecycle('Singleton'),
          :block(sub {
              ...
              return MyStorage.new;
          }),
      )
  );

  $c.add-service(
      'app', IoC::BlockInjection.new(
          :class('MyApp'),
          :lifecycle('Singleton'),
          :dependencies({
              'logger'  => 'logger',
              'storage' => 'storage',
          }),
      )
  );

 

DESCRIPTION

Used in the container class for each component. See L<IoC::Container> for an example of use of this class. See L<IoC> for a more sweetened way to build your container.

METHODS

(item) add-service(C<$name>, C<$service>)
Adds a service (L<IoC::Service> object) to your container
(item) fetch('')
Returns the service provided by the string.
(item) resolve(service => '')
Returns the object the service generates (equivalent to fetch('<service ').get()>)

BUGS

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or post an issue to http://github.com/jasonmay/perl6-ioc/

REFERENCE

(item) L

AUTHOR

Jason May, <jason.a.may@gmail.com>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: