Skip to content

miguelriverarios/MRR-Simple-Inject-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MRR Simple Inject IOC Framework

Make sure to review the roadmap and current limitations before using.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

This project started as a technical assignment for a job application, but, in building out the library, I thought it would be a good opportunity to get into the weeds a bit on what makes a good library. This will be an ever evolving project taking into account best practices as I come across them. As a bonus, this provides a minimal implenetation for a functioning dependency injection framework.

Things You Should be Familiar With

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

Make sure you have node and npm installed.

To check if you have Node.js installed, run this in your terminal:

node -v

If your terminal returns a version number, you're good to go. npm is distributed with Node.js, so if you have node, you should have npm, but to confirm, run this in your terminal:

npm -v

Go here if you do not have node installed. If you want to update npm, use the following command in terminal:

npm install npm@latest -g

My go to package manager is yarn. You can get yarn via the following command (this is optional):

npm install --global yarn

Installation

  1. Clone the repo into your local directory

    git clone https://github.com/miguelriverarios/MRR-Simple-Inject-Library.git
  2. Install NPM packages

    npm install

    or with yarn

    yarn
    

Testing

Tests are performed using the jasmine-karma framework. To run the test methods, use the following command:

npm test

Or with yarn:

yarn test

If successful, a browser window will open showing test results.

Usage

This library provides a simple framework for implementing dependency injectio via an IoC container. Let's say you have a class representing a Superhero like so:

class Superhero {
    constructor(superpower) {
        this.superpower = superower;
    }
}

A Superhero isn't a superhero without a Superpower, so let's pretend Superpower is defined as such:

class Superpower {
    constructor() {
        this.ability = "heat vision";
    }
}

Normally you'd have to define these sequentially before instantiating a Superhero, but with this library you can do it like so:

require("/src/injection.js");
const inject = new SimpleInject();

class Superhero {
    constructor(superpower) {
        this.superpower = superpower;
    }
}
inject.register("superhero", ["superpower", Superhero]);

class Superpower {
    constructor() {
        this.ability = "heat vision";
    }
}
inject.register("superpower", [Superpower]);

const superhero = inject.get("superhero");

console.log(superhero.superpower.ability); // heat vision

Roadmap

See the open issues for a list of proposed features (and known issues).

Current Limitations

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

All additional features should include corresponding test methods.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Miguel Rivera Rios - miguel.e.rivera.rios@gmail.com

Project Link: https://github.com/miguelriverarios/MRR-Simple-Inject-Library

Acknowledgements

About

Simple framework for implementing dependency injection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published