Skip to content

Commit f593328

Browse files
committed
docs(readme): re-structure the content
1 parent 40714c4 commit f593328

1 file changed

Lines changed: 47 additions & 18 deletions

File tree

README.md

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,11 @@ composer require algoyounes/bindify
2424

2525
## Usage
2626

27-
### Supported Bind Types
28-
- `BindType::Singleton`: Keeps one instance and shares it everywhere.
29-
- `BindType::Transient`: Creates a new instance every time you use it.
27+
### Basic Binding
3028

31-
### Define your interface and implementation
32-
33-
1. Use the `#[BindWith]` attribute to bind an interface to its implementation
34-
35-
> [!NOTE]
36-
> You can bind multiple services by passing them as an array :
37-
> ```php
38-
> #[BindWith([DefaultService::class, ... ], BindType::Singleton)]
39-
> ```
29+
Define your interface with the `#[BindWith]` attribute:
4030

4131
```php
42-
namespace App\Contracts;
43-
4432
use AlgoYounes\Bindify\Attributes\BindWith;
4533
use AlgoYounes\Bindify\Attributes\BindType;
4634

@@ -51,22 +39,63 @@ interface ServiceContract
5139
}
5240
```
5341

54-
2. Create the implementation of the interface
42+
Create your implementation:
5543

5644
```php
57-
namespace App\Services;
58-
5945
use App\Contracts\ServiceContract;
6046

6147
class DefaultService implements ServiceContract
6248
{
6349
public function execute()
6450
{
65-
// Your implementation here
51+
// Your implementation
6652
}
6753
}
6854
```
6955

56+
### Binding Types
57+
58+
| Type | Description |
59+
|-----------------------|-------------------------------------|
60+
| `BindType::Singleton` | Shares the same instance everywhere |
61+
| `BindType::Transient` | Creates a new instance each time |
62+
63+
### Advanced Binding
64+
65+
#### Multiple Implementations
66+
67+
Bind multiple implementations to an interface:
68+
69+
```php
70+
#[BindWith([DefaultService::class, AlternativeService::class], BindType::Singleton)]
71+
interface ServiceContract
72+
{
73+
// ...
74+
}
75+
```
76+
77+
#### Tagged Bindings
78+
79+
Explicitly tag your bindings:
80+
81+
```php
82+
#[BindWith([DefaultService::class], BindType::Singleton, tag: 'primary')]
83+
```
84+
85+
When no tag is provided and the size of services greater than one, Bindify will auto-generate one based on the implementation class name appended with '_tag'
86+
87+
### Retrieving Bindings
88+
89+
Resolve your bindings as usual through container:
90+
91+
```php
92+
// Single binding
93+
$service = app(ServiceContract::class);
94+
95+
// Tagged bindings
96+
$services = app()->tagged('primary');
97+
```
98+
7099
## License
71100

72101
This package is open-sourced software licensed under the [MIT license](LICENSE).

0 commit comments

Comments
 (0)