Herbs Simple Container Services
The purpose of this tool is to make it more scalable and make service dependency management easier in your applications.
container
.addAsFunction(userRepository)
.addAsClass(UserService)
.addAsValue('cache', cache)
.addAsFunction(getUsersUseCase);
const useCase = container.factoryContainer().getUsersUseCase;
var output = await useCase.run({ name: 'Kenedy' });
Make sure you have Node.js installed.
git clone https://github.com/maikmb/herbs-di.git # or clone your own fork
cd herbs-di
npm install
To use HerbsJS with express serve you can use useHerbsDi
middleware to configure container like bellow:
const app = express()
const port = 3000
app.use(useHerbsDi(injection))
app.get('/', async (req, res) => {
const { getUsersUseCase } = req.injection;
const ret = await getUsersUseCase.run({ name: 'Jhon' });
if (ret.isOk) {
res.send({ users: ret.value });
return;
}
res.send({ error: ret.err })
})
dev:console
to run an example di container consoledev:express
to run an API with express middleware for the di containerdev:gql
to run an api with graphql middleware for the di container (under construction)