0.5.0 • Published 11 months ago

dizy v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Getting Started

Installation

npm install dizy

Simple usage

import { ContextContainerFactory, SingletoneConfig } from "dizy";

// Create array of di object configurations
const diObjectsConfigs = [
     // Singletone object config
    new SingletoneConfig(
        'carService', // name of DI Object
        CarService // DI Object class or function
    ),
    new SingletoneConfig('engineService', EngineService),
];

// Class of your app where you want to use DI
// It's just an example, you can use it anywhere
class App {
    constructor() {
        // Next to lines of code is needed for configuring your DI Context
        this.context = ContextContainerFactory.createContainer(diObjectsConfigs, 'appContext');
        this.context.init(); // Runs the context
    }

    start() {
        const carService = this.context.getInstance('carService'); // Getting instance of your DI Object
        carService.check();
    }
}

class CarService {
    constructor(engineService) { // name of constructor parameter must be equal to name of object in DI Context
        this.engineService = engineService;
    }

    check() {
        this.engineService.pressure();
    }
}

class EngineService {
    constructor() { }

    pressure() {
        console.log('Pressure is high!');
    }
}

Introduction

Welcome to the documentation of Dizy! This library provides a powerful and flexible solution for managing dependencies in your applications, making it easier to write maintainable and testable code.

Dependency injection is a design pattern that allows you to decouple components from their dependencies, making them more reusable and easier to test. With our DI library, you can easily inject dependencies into your components, allowing them to focus on their core functionality.

The library offers a simple and intuitive API, making it easy to get started with dependency injection.

In this documentation, we'll cover everything you need to know about using Dizy. We'll start with an overview of the library's features and how they can benefit your projects. Then, we'll dive into specific examples of how to use the library in different scenarios. Finally, we'll provide some tips and best practices for working with the library effectively.

Let's get started and explore the power of dependency injection with Dizy!

Goals

  1. Help the developer write more reliable and easy to read code.
  2. Simplify and speed up the development process.
  3. Allow you to commit the results of architectural analysis in the software objects form.
  4. Provide the ability to quickly replace or disable software objects.
  5. Ensure compliance with the lifecycle of objects and provide an opportunity to create special lifecycles.
  6. Provide tools for configuring objects

Review of approaches

Service Locator

Dependency Injection

Dizy multilifecycle

Other implementations and performance overview

Authors

Supporters

Become a sponsor on patreon

Become a sponsor on opencollective to get your company in front of future thousands of engaged developers and help us out!

Love Dizy? Give our repo a star :star: :arrow_up:.

0.4.7

11 months ago

0.5.0

11 months ago

0.4.5

11 months ago

0.4.6

11 months ago

0.4.4

11 months ago

0.4.3

11 months ago

0.4.2

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.3.2

12 months ago