Skip to content

Instantly share code, notes, and snippets.

@kenanhancer
Created April 24, 2020 21:03
Show Gist options
  • Save kenanhancer/a0a0cd66388d7b48d2a425611d65df5c to your computer and use it in GitHub Desktop.
Save kenanhancer/a0a0cd66388d7b48d2a425611d65df5c to your computer and use it in GitHub Desktop.
nut-ioc loading dependencies with directory path and programatic dependency definition
const nutIoc = require('nut-ioc');
const nutIocContainer = nutIoc();
const mainAsync = async () => {
const ignoredDependencies = ['node_modules',
'.env',
'*.json',
'.idea',
'.git',
'.gitignore',
'*.iml',
'.*',
'*.md',
'LICENSE'];
nutIocContainer.use({ dependencyPath: './', ignoredDependencies });
nutIocContainer.useDependency({
ServiceName: "authorBasicInfo",
Service: ({firstName: "Kenan", lastName: "Hancer"})
});
nutIocContainer.useDependency({
ServiceName: "authorWithContacts",
Service: ({authorBasicInfo}) => ({...authorBasicInfo, city: "London", mail: "kenanhancer@gmail.com"})
});
const { greetingService } = await nutIocContainer.build();
const helloMsg = greetingService.sayHello(authorWithContacts);
console.log(helloMsg);
const goodBydMsg = greetingService.sayGoodbye(authorWithContacts);
console.log(goodBydMsg);
};
mainAsync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment