Created
April 12, 2013 21:52
-
-
Save stevan/5375448 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env perl | |
use v5.16; | |
use Bread::Board; | |
use Data::Dumper; | |
{ | |
package OurApp::ServiceDiscovery; | |
use Moose::Role; | |
package OurApp::ServiceDiscovery::Distributed; | |
use Moose; | |
with 'OurApp::ServiceDiscovery'; | |
package OurApp::ServiceDiscovery::Local; | |
use Moose; | |
with 'OurApp::ServiceDiscovery'; | |
package OurApp::Worker; | |
use Moose; | |
has 'service_discoverer' => ( | |
is => 'ro', | |
does => 'OurApp::ServiceDiscovery', | |
required => 1 | |
); | |
} | |
my $prod_discoverer = container 'ProductionZeroMQStrategy' => as { | |
service 'discoverer' => ( | |
class => 'OurApp::ServiceDiscovery::Distributed' | |
); | |
}; | |
my $dev_discoverer = container 'DevZeroMQStrategy' => as { | |
service 'discoverer' => ( | |
class => 'OurApp::ServiceDiscovery::Local' | |
); | |
}; | |
my $our_app_container = container 'OurApp' => [ 'ZeroMQStrategy' ] => as { | |
service 'some_worker' => ( | |
class => 'OurApp::Worker', | |
dependencies => { | |
service_discoverer => depends_on('ZeroMQStrategy/discoverer') | |
} | |
); | |
}; | |
my $app_dev = $our_app_container->create( 'ZeroMQStrategy' => $dev_discoverer ); | |
say Dumper $app_dev->resolve( service => 'some_worker' ); | |
my $app_prod = $our_app_container->create( 'ZeroMQStrategy' => $prod_discoverer ); | |
say Dumper $app_prod->resolve( service => 'some_worker' ); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment