Download the PHP package intraworlds/service-container without Composer
On this page you can find all versions of the php package intraworlds/service-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download intraworlds/service-container
More information about intraworlds/service-container
Files in intraworlds/service-container
Package service-container
Short Description Lightweight yet powerful implementation of dependancy injection container with autowiring
License MIT
Informations about the package service-container
Lightweight yet powerful implementation of dependancy injection container with autowiring.
Installation
Use Composer to install the package:
Usage
The container is implementing standard PSR-11 interface. You can use it with autowiring out-of-the-box.
Let's say that we're building a cache client. This client will not implement a cache directly but only provides common API - it will depend on given adapter.
We'll start will start with defining memory adapter
Cache client
Now in the main program we can instantiate cache client with ease - dependancy of the client will be resolved automatically.
Our still implementing serialization by itself. Let's move it into dependancy.
And little change in the client.
Our main code will stay the same.
Method resolve
is useful for resolving any dependencies of a callable. Especially it's useful for init
template method. See following example.
Manual Wiring
Sometimes you want to configure container manually. Let's consider following example on Command Pattern
With IW\ServiceContainer
you have several options how to resolve OrderInvoker
's dependencies.
Arguably all approaches have their advantages. internal factory approach is good for static analysis. wiring factory is useful for common application pattern and when dependencies may vary.
TODO keep going with examples
TODO
License
All contents of this package are licensed under the MIT license.