av / bonefish-di
This Project maintains the Bonefish Dependency Injection Container
Installs: 77
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/av/bonefish-di
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2019-02-20 18:10:44 UTC
README
Bonefish-DI is a dead simple and small Dependency Injection Container.
Features
- No outside dependencies
- Inject services with @inject annotation
- Lazy dependency injection by default
Installation
Please use Composer to install this package.
$ composer require av/bonefish-di:dev-master
Usage
Simple creating with injection without adding it into the container
// Create an Object and inject all Services $container = new Bonefish\DependencyInjection\Container(); $foo = $container->create('\Some\Random\Class'); // or with parameters $bar = $container->create('\Some\Random\Class',array('bar','baz'));
Create a new service and save it in the container
// Create a service, no parameters here $container = new Bonefish\DependencyInjection\Container(); $service = $container->get('\Some\Random\Service');
You can also create Objects and add them later to be used as services
// Create an Object and inject all Services $container = new Bonefish\DependencyInjection\Container(); $bar = $container->create('\Some\Random\Class',array('bar','baz')); $container->add('\Some\Random\Class',$bar);
You can also define aliases
// Create an Object and inject all Services $container = new Bonefish\DependencyInjection\Container(); $service = $container->get('\Some\Random\Service'); $container->alias('Alias','\Some\Random\Service'); // This will now return \Some\Random\Service $service2 = $container->get('Alias');
You can also check if an alias is set, tear down the whole container and list all services in this container.