Injector

Dependency injector

Injector

A perl6 dependency injector

Synopsys

use lib "lib";

use Injector;

class Rand {
    has $.r = ("a" .. "z").roll(rand * 10).join;
}

class C2 {
    has Int $.a is injected
}

class C1 {
    has C2      $.c2    is injected;
    has Int     $.b     is injected<test>;
    has Rand    $.r     is injected{:lifecycle<instance>};
}

BEGIN {
    bind 42;
    bind 13, :name<test>;
}

my C1 $c is injected;
say $c;                     # C1.new(c2 => C2.new(a => 42), b => 13, r => Rand.new(r => "qo"))

for ^3 {
    given C1.new: :123b {
        .c2.a.say;          # 42                            42                          42
        .b.say;             # 123                           123                         123
        .r.say;             # Rand.new(r => "ztjbpvqka")    Rand.new(r => "zsmqnrr")    Rand.new(r => "wmsq")
    }
}

Injector v0.0.1

Dependency injector

Authors

  • Fernando Corrêa de Oliveira

License

NOASSERTION

Dependencies

Test Dependencies

Provides

  • Injector
  • Injector::Bind
  • Injector::Bind::Clone
  • Injector::Bind::Instance
  • Injector::Bind::ObjectType
  • Injector::Bind::Singleton
  • Injector::Injected
  • Injector::Injected::Attribute
  • Injector::Injected::Variable
  • Injector::Storage

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.