npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@thefoxjob/js-service-provider

v1.0.4

Published

Service Provider where you can register your IoC bindings

Downloads

7

Readme

Js Service Provider

Service Provider abstraction that allows you to register your IoC bindings.

It acts as support components for the @aedart/js-ioc package. Please check it out, before you continue reading.

Furthermore, just like the @aedart/js-ioc package, this too is inspired by Taylor Otwell's Laravel version of Service Providers.

Contents

How to install

npm install @aedart/js-service-provider

Quick start

Prerequisite

The Service Provider abstraction is meant to offer a place where you can register your IoC bindings, as well as application bootstrapping. It has been designed to work with the @aedart/js-ioc package - Yet, there is no type check hereof, meaning that any Service Container can be used.

In any case, you should have some understanding of what IoC means and

Create a provider

import ServiceProvider from '@aedart/js-service-provider';

class MyBoxServiceProvider extends ServiceProvider {

    register(){
        // Register box
        this.ioc.bind('my-box', (ioc, params) => {
            return new Box(params);
        });
    }

    boot(){
        // ... not shown ... //
    }
}

Register and boot provider

There are two ways that you can register your provider;

  1. You can register and boot your provider manually
  2. You can use the Service Registrar

Manually

Given that you have an IoC ready to be used, somewhere in your application bootstrap logic.

let provider = new MyBoxServiceProvider(IoC);

// Register bindings
provider.register();

// Boot the services
provider.boot();

Service Registrar

The Service Registrar allows you to register and boot a bulk of providers. It also keeps track of the provider's boot state; has boot or not!

import { Registrar } from '@aedart/js-service-provider';

let registrar = new Registrar(IoC);

// ... Given that you have a set of service providers ... //

// Register and boot
registrar.registerProviders([
    CalculatorServiceProvider,
    MyBoxServiceProvider,
    GfxServiceProvider,
    AnimationServiceProvider
]);

Delay booting of providers

Sometimes it is useful to register your providers, but not to boot them straight away.

import { Registrar } from '@aedart/js-service-provider';

let registrar = new Registrar(IoC);

// ... Given that you have a set of service providers ... //

// Register - but do NOT boot
registrar.registerProviders([
    CalculatorServiceProvider,
    MyBoxServiceProvider,
    GfxServiceProvider,
    AnimationServiceProvider
], false);

// Later in your application ...
registrar.bootProviders();

Check out the Registrar's source code, for additional information.

Contribution

Have you found a defect ( bug or design flaw ), or do you wish improvements? In the following sections, you might find some useful information on how you can help this project. In any case, I thank you for taking the time to help me improve this project's deliverables and overall quality.

Bug Report

If you are convinced that you have found a bug, then at the very least you should create a new issue. In that given issue, you should as a minimum describe the following;

  • Where is the defect located
  • A good, short and precise description of the defect (Why is it a defect)
  • How to replicate the defect
  • (A possible solution for how to resolve the defect)

When time permits it, I will review your issue and take action upon it.

Fork, code and send pull-request

A good and well written bug report can help me a lot. Nevertheless, if you can or wish to resolve the defect by yourself, here is how you can do so;

  • Fork this project
  • Create a new local development branch for the given defect-fix
  • Write your code / changes
  • Create executable test-cases (prove that your changes are solid!)
  • Commit and push your changes to your fork-repository
  • Send a pull-request with your changes
  • Drink a Beer - you earned it :)

As soon as I receive the pull-request (and have time for it), I will review your changes and merge them into this project. If not, I will inform you why I choose not to.

Acknowledgement

Versioning

This package follows Semantic Versioning 2.0.0

License

BSD-3-Clause, Read the LICENSE file included in this package