5 use Catalyst::IOC::ConstructorInjection;
7 # FIXME - All of these imports need to get the importing package
8 # as the customise_container and current_container variables
9 # NEED to be in the containers package so there can be multiple
11 use Sub::Exporter -setup => {
17 groups => { default => [qw/
23 #use Sub::Exporter -setup => [
26 # Bread::Board::container
27 # Bread::Board::depends_on
28 # Bread::Board::service
30 # Bread::Board::wire_names
31 # Bread::Board::include
32 # Bread::Board::typemap
36 # I'm probably doing it wrong.
37 # Anyway, I'll just use Moose::Exporter. Do I really have to use Sub::Exporter?
39 #Moose::Exporter->setup_import_methods(
40 # also => ['Bread::Board'],
42 our $customise_container;
43 our $current_container;
47 $customise_container = sub {
48 warn("In customise container");
49 local $current_container = shift();
56 local $current_container = $current_container->get_sub_container('model');
61 my ($name, %args) = @_;
62 $args{dependencies} ||= {};
63 $args{dependencies}{application_name} = depends_on( '/application_name' );
65 # FIXME - check $args{type} here!
67 my $service = Catalyst::IOC::ConstructorInjection->new(
70 lifecycle => 'Singleton',
71 # XX FIXME - needs to become possible to intuit catalyst_component_name
72 # from dependencies (like config)
73 catalyst_component_name => 'TestAppCustomContainer::Model::Bar',
75 $current_container->add_service($service);
80 # FIXME - should the code example below be on this file or Catalyst::IOC::Container?
88 Catalyst::IOC - IOC for Catalyst, based on Bread::Board
92 package MyApp::Container;
98 container $self => as {
99 container model => as {
104 # model Bar needs model Foo to be built before
105 # and Bar's constructor gets Foo as a parameter
106 component Bar => ( dependencies => [
107 depends_on('/model/Foo'),
110 # Baz is rebuilt once per HTTP request
111 component Baz => ( lifecycle => 'Request' );
113 # built only once per application life time
114 component Quux => ( lifecycle => 'Singleton' );
116 # built once per app life time and uses an external model,
117 # outside the default directory
118 # no need for wrappers or Catalyst::Model::Adaptor
120 lifecycle => 'Singleton',
121 class => 'My::External::Class',
133 Catalyst Contributors, see Catalyst.pm
141 This library is free software. You can redistribute it and/or modify it under
142 the same terms as Perl itself.