The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::DI - Perl dependency injection container

SYNOPSIS configuration by yaml

  injections:
   - name: hoge
     class_name: Hoge
     injection_type: setter
     instance_type: prototype
     properties:
       name: hoge
   - name: fuga
     class_name: Fuga
     injection_type: constructer
     instance_type: singleton
     properties:
       name: fuga
   - name: hogehoge
     class_name: HogeHoge
     injection_type: constructer
     instance_type: singleton
     properties:
       hogehoge: 
         name: fugafuga
         class_name: FugaFuga
         injection_type: constructer
         instance_type: singleton
         properties:
           name: fugafuga
  

  my $di = Class::DI->yaml_container($yaml_filepath);
  # set from set_name method
  # $hoge->set_name("hoge"); 
  my $hoge = $di->get_component("hoge"); 
  print $hoge->get_name; # hoge

  # set from constructer 
        # Fuga->new({name=>"fuga"});
        my $fuga = $di->get_component("fuga"); 
  print $fuga->get_name; # fuga

        # nested class 
        my $hogehoge = $di->get_component("hogehoge"); 
  print $hogehoge->get_fugafuga->get_name; # fugafuga

DESCRIPTION

this class does DI. The instance is generated based on an external setting, and the dependence between components is excluded from the source code.

SEE ALSO

AUTHOR

Masafumi Yoshida, <masafumi.yoshida820@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2010 by masafumi yoshida

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.