1.0.0 • Published 7 years ago

hapi-servicecontainer v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

hapi-servicecontainer

CircleCI

This module is a dependency injection module for the hapi framework. It's inspired from the symfony framework.

Install

npm i hapi-servicecontainer --save

Register plugin

server.register([
{
    register: require('hapi-servicecontainer'),
    options: {
        file: Path.resolve(__dirname, './Config/Parameters.json')
    }
}],
() => {
    ...
});

The plugin uses one option called file. This is the file, which points to your settings. The detail of that file is the same as here since this plugin is based in the servicecontainer module.

Usage

After you registered the plugin, you have access to your services and parameters via the request parameter passed to your handler.

Run service method

server.route({
    method: 'GET',
    path: '/',
    handler: (req, reply) => {
        reply(req.container.get('foo').getHello());
    }
})

or get a parameters

server.route({
    method: 'GET',
    path: '/',
    handler: (req, reply) => {
        reply(req.container.getParameter('name'));
    }
})