4 use Bread::Board qw/depends_on/;
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 => {
18 groups => { default => [qw/
25 #use Sub::Exporter -setup => [
28 # Bread::Board::container
29 # Bread::Board::depends_on
30 # Bread::Board::service
32 # Bread::Board::wire_names
33 # Bread::Board::include
34 # Bread::Board::typemap
38 # I'm probably doing it wrong.
39 # Anyway, I'll just use Moose::Exporter. Do I really have to use Sub::Exporter?
41 #Moose::Exporter->setup_import_methods(
42 # also => ['Bread::Board'],
44 our $customise_container;
45 our $current_container;
49 $customise_container = sub {
50 warn("In customise container");
51 local $current_container = shift();
58 local $current_container = $current_container->get_sub_container('model');
63 my ($name, %args) = @_;
64 $args{dependencies} ||= {};
65 $args{dependencies}{application_name} = depends_on( '/application_name' );
67 # FIXME - check $args{type} here!
69 my $service = Catalyst::IOC::ConstructorInjection->new(
72 lifecycle => 'Singleton',
73 # XX FIXME - needs to become possible to intuit catalyst_component_name
74 # from dependencies (like config)
75 catalyst_component_name => 'TestAppCustomContainer::Model::Bar',
77 $current_container->add_service($service);
82 # FIXME - should the code example below be on this file or Catalyst::IOC::Container?
90 Catalyst::IOC - IOC for Catalyst, based on Bread::Board
94 package MyApp::Container;
100 container $self => as {
101 container model => as {
106 # model Bar needs model Foo to be built before
107 # and Bar's constructor gets Foo as a parameter
108 component Bar => ( dependencies => [
109 depends_on('/model/Foo'),
112 # Baz is rebuilt once per HTTP request
113 component Baz => ( lifecycle => 'Request' );
115 # built only once per application life time
116 component Quux => ( lifecycle => 'Singleton' );
118 # built once per app life time and uses an external model,
119 # outside the default directory
120 # no need for wrappers or Catalyst::Model::Adaptor
122 lifecycle => 'Singleton',
123 class => 'My::External::Class',
135 Catalyst Contributors, see Catalyst.pm
143 This library is free software. You can redistribute it and/or modify it under
144 the same terms as Perl itself.