Skip to content

Instantly share code, notes, and snippets.

Created May 1, 2022 15:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
use Cspray\AnnotatedContainer\Attribute\Service;
use Cspray\AnnotatedContainer\Attribute\Inject;
use Cspray\AnnotatedContainer\ParameterStore;
use Cspray\Typiphy\Type;
class MySecretParameterStore implements ParameterStore {
public function getName() : string {
return 'secrets';
public function fetch(Type $type, string $key) : mixed {
// Something you'd implement to retrieve the value from your secrets store
return fetchFromVaultOrAwsSecretsOrSomewhereElseSafe($key);
class SomeApiClient {
public function __construct(
#[Inject('my-api-key', from: 'secrets')]
private readonly string $apiKey
) {}
$compiler = ContainerDefinitionCompilerFactory::withoutCache()->getCompiler();
$containerDefinition = $compiler->compile(
ContainerDefinitionCompileOptionsBuilder::scanDirectories(__DIR__ . '/src')->build()
$containerFactory = new AurynContainerFactory();
$containerFactory->addParameterStore(new MySecretParameterStore());
$container = $containerFactory->createContainer($containerDefinition);
// The value returned from they 'my-api-key' passed to MyParameterStore::fetch will be injected
$myClient = $container->get(SomeApiClient::class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment