27 Dec 22:04
RFC: IOC Configuration syntax/mini-language
Stevan Little <stevan <at> iinteractive.com>
2004-12-27 21:04:40 GMT
2004-12-27 21:04:40 GMT
So I have been using my module IOC a lot lately, so far so good, but I
have found that writing the code to create all the containers and
services and such gets quite tedious. For instance to do a basic DBI
container, I do something like this:
my $r = IOC::Registry->new('MyApp');
my $c = IOC::Container->new('DBI');
$c->register(IOC::Service::Literal->new('dsn' =>
'dbi:mysql:test'));
$c->register(IOC::Service::Literal->new('username' => 'test'));
$c->register(IOC::Service::Literal->new('password' => '****'));
$c->register(IOC::Service::ConstructorInjection->new('connection' => (
'DBI', 'connect' [
IOC::Service::ConstructorInjection->ComponentParameter('dsn'),
IOC::Service::ConstructorInjection->ComponentParameter('username'),
IOC::Service::ConstructorInjection->ComponentParameter('password')
]
)));
$r->registerContainer($c);
# ... then in my app all I have to do is
my $reg = IOC::Registry->instance();
my $db_conn = $reg->locateService('/MyApp/DBI/connection');
Writing the code to configure the services, containers and registry
though, can get quite tiring. Fortunately, I really only need to do
this once and then just use it, but ideally I would like it to be a
little less taxing on the carpal tunnel.
(Continue reading)
> > But, I personally wouldn't have code in your config files. Instead, I
> > would do what I suggested earlier and build the code from basic
> > concepts.
>
> Well part of the problem is that IOC::Service requires a code-ref. The
> ConstructorInjection and SetterInjection ones do not, but you can't
> always fit something into one of those. IOC::Service provides a nice
> bridge to do both ConstructorInjection and SetterInjection at the same
RSS Feed