4 use Bread::Board qw/depends_on/;
5 use Catalyst::IOC::ConstructorInjection;
8 use Sub::Exporter -setup => {
15 groups => { default => [qw/
26 ${"${caller}::customise_container"} = sub {
27 local ${"${caller}::current_container"} = shift;
35 local ${"${caller}::current_container"} = ${"${caller}::current_container"}->get_sub_container('model');
40 my ($name, %args) = @_;
42 $args{dependencies} ||= {};
43 $args{dependencies}{application_name} = depends_on( '/application_name' );
45 my $lifecycle = $args{lifecycle};
46 my %catalyst_lifecycles = map { $_ => 1 } qw/ COMPONENTSingleton Request /;
47 $args{lifecycle} = $lifecycle
48 ? $catalyst_lifecycles{$lifecycle} ? "+Catalyst::IOC::LifeCycle::$lifecycle" : $lifecycle
52 # FIXME - check $args{type} here!
54 my $component_name = join '::', (
55 ${"${caller}::current_container"}->resolve(service => '/application_name'),
56 ucfirst(${"${caller}::current_container"}->name),
60 my $service = Catalyst::IOC::ConstructorInjection->new(
63 catalyst_component_name => $component_name,
65 ${"${caller}::current_container"}->add_service($service);
76 Catalyst::IOC - IOC for Catalyst, based on Bread::Board
80 package MyApp::Container;
86 container $self => as {
87 container model => as {
92 # model Bar needs model Foo to be built before
93 # and Bar's constructor gets Foo as a parameter
94 component Bar => ( dependencies => [
95 depends_on('/model/Foo'),
98 # Baz is rebuilt once per HTTP request
99 component Baz => ( lifecycle => 'Request' );
101 # built only once per application life time
102 component Quux => ( lifecycle => 'Singleton' );
104 # built once per app life time and uses an external model,
105 # outside the default directory
106 # no need for wrappers or Catalyst::Model::Adaptor
108 lifecycle => 'Singleton',
109 class => 'My::External::Class',
121 Catalyst Contributors, see Catalyst.pm
129 This library is free software. You can redistribute it and/or modify it under
130 the same terms as Perl itself.