Created
July 25, 2011 22:36
-
-
Save andrewalker/1105428 to your computer and use it in GitHub Desktop.
rafl explanation of components in the container (excerpt from irc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
so, we got this service subclass doing ACCEPT_CONTEXT and COMPONENT, right? | |
or two of them, or whatever | |
instances of that are generated while building the "default" container for your app | |
based on the components in your lib/ and whatnot | |
what you want to know is how to: | |
a) configure additional services in that container | |
super simple | |
container $default_container => as { more services }; | |
b) make component services depend on that | |
trickier, as i can't think of a nice way to "amend" service definitions | |
but | |
if you're declaring dependencies for a catalyst component thing, you already must specify at least its name | |
which is basically all there is to a component service right now | |
plus the custom service class | |
so you might as well re-declare the whole component service | |
for that, all we need is an exporter | |
providing a service() like sugar for components | |
and making sure existing services actually get overridden and all that. not sure how the default container behaves when doing that | |
so you got $default_container, containing a Model::Foo, or whatever | |
you do | |
container $default_container => as { | |
service model => ...; # some constructor injection to MyApp::Model or something | |
container Model => as { | |
component Foo => (dependencies => ['/model']); | |
}; | |
}; | |
which would build the constructor injection as it currently does, defaulting to the class name in the right namespace as declared by the surrounding container | |
as well as adding using the catalyst-specific service class | |
class MyApp::Container extends Catalyst::Container { | |
method BUILD { container $self => as { ... } } | |
}; | |
c) ask for those services declared in a) outside of a web context | |
simple as well. $customised_container->fetch('service')->get # or whatever the api was |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment