Skip to content

Bindify is a laravel package that simplifies attribute-based dependency injection

License

Notifications You must be signed in to change notification settings

algoyounes/Bindify

Repository files navigation

Bindify Logo
Bindify

Build Status Total Downloads Latest Stable Version License

Bindify is a Laravel package that provides a simple way to bind interfaces to their implementations using attributes.

Installation

You can install the package via composer:

composer require algoyounes/bindify

Usage

Supported Bind Types

  • BindType::Singleton: Keeps one instance and shares it everywhere.
  • BindType::Transient: Creates a new instance every time you use it.

Define your interface and implementation

  1. Use the #[BindWith] attribute to bind an interface to its implementation
namespace App\Contracts;

use AlgoYounes\Bindify\Attributes\BindWith;
use AlgoYounes\Bindify\Attributes\BindType;

#[BindWith(DefaultService::class, BindType::Singleton)]
interface ServiceContract
{
    public function execute();
}
  1. Create the implementation of the interface
namespace App\Services;

use App\Contracts\ServiceContract;

class DefaultService implements ServiceContract
{
    public function execute()
    {
        // Your implementation here
    }
}

About

Bindify is a laravel package that simplifies attribute-based dependency injection

Topics

Resources

License

Stars

Watchers

Forks