DEV Community

Cover image for I made an Async Service Container for Node/Browser
Andrew Stacy
Andrew Stacy

Posted on

I made an Async Service Container for Node/Browser

Hey friends,

Over the years I have implemented service container architecture in many large-scale front-end apps and it has vastly improved their performance and maintainability. I've finally got around to turning it into an open-source library called "Be Our Guest." The name is inspired by the Disney song from Beauty and the Beast and the lyric "put our service to the test."

So, what is it "Be Our Guest?"

It is an ASYNC service container that enables your node or browser applications to implement an Inversion of Control architecture for it's modules and dependencies. You may be thinking, "why do I need this?"

As an example to illustrate it's value, let's say we have a module that handles auth within our application. After you construct and register the module it requires a boot step to send some requests to the backend system to retrieve auth tokens that our other API modules will require. This action is an asynchronous action and we do not want to block initialization of our other modules while this module makes its request. We also need to inject this module into other modules that depend on the auth token. Those modules must await the initialization of our token module before they can be used. As you can see, providing async support for these types of initialization are crucial.

Why not use X other service container library?

There are quite a few other service container libraries out there, but most of them require decorator support for your applications which is not an official JS api and will make adoption into an existing application more difficult (as you will have to do some refactoring). The primary reason they do this is to enable automatic dependency injection. While auto-DI is a nice feature, it's not a hard requirement for an IoC service container to be useful.

Also, Be Our Guest is completely async. This enables you to more easily register and boot dependencies that require async operations. It also allows the service container to register and boot all of your services without them blocking each other in the process, further increasing your app's performance.

Check it out!

Please take a look at "Be Our Guest" and give us a star at https://github.com/AJStacy/be-our-guest .

Top comments (0)