Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function main() {
const ctx = new Context('request');
// Add EnglishGreeter for now
ctx.add(createBindingFromClass(EnglishGreeter, {namespace: 'greeters'}));
// Add ChineseGreeter
ctx
.bind('greeters.ChineseGreeter')
.toClass(ChineseGreeter)
.tag('greeter');
const enlishGreeterBinding = ctx.getBinding('greeters.EnglishGreeter');
console.log(enlishGreeterBinding.key);
let possibleEnglishGreeters = ctx.find('*.EnglishGreeter');
console.log(possibleEnglishGreeters.map(b => b.key));
export async function main() {
const ctx = new Context('request');
// Bind request context
ctx.bind(REQUEST_CONTEXT).to(ctx);
const binding = createBindingFromClass(TracingInterceptor, {
key: TRACING_INTERCEPTOR,
});
ctx.add(binding);
let count = 1;
const reqUuidGenerator: RequestIdGenerator = context =>
`[${context.name}] ${count++}`;
ctx.bind(REQUEST_ID_GENERATOR).to(reqUuidGenerator);
ctx.bind(GREETER).toClass(Greeter);
ctx
.bind(CONVERTER)
.toClass(Converter)
export async function main() {
const ctx = new Context('request');
// Bind greeting service
ctx.bind(GREETING_SERVICE).toClass(GreetingService);
// Set the current date to a factory function
ctx.bind(CURRENT_DATE).toDynamicValue(getCurrentDate);
// Set the current user to `John` (a constant value)
ctx.bind('currentUser').to('John');
// Set the current language to `zh`
ctx.bind('currentLanguage').to('zh');
// Add EnglishGreeter for now
ctx
.bind('greeters.EnglishGreeter')
export async function main() {
const appCtx = new Context('app');
// Create a context per request, with `appCtx` as the parent
const requestCtx = new Context(appCtx, 'request');
const greeterBinding = appCtx
.bind('services.Greeter')
.toClass(Greeter)
.tag('greeter');
// Set prefix to `app` at app context level
appCtx.bind('prefix').to(appCtx.name);
// Get a greeter from request context
let greeter = await requestCtx.get(greeterBinding.key);
// Inherit `prefix` from app context
it('returns undefined if no auth metadata is defined', async () => {
const context: Context = new Context();
context
.bind(CoreBindings.CONTROLLER_CLASS)
.to(ControllerWithNoMetadata);
context.bind(CoreBindings.CONTROLLER_METHOD_NAME).to('whoAmI');
context
.bind(CoreBindings.CONTROLLER_METHOD_META)
.toProvider(AuthMetadataProvider);
const authMetadata = await context.get(
CoreBindings.CONTROLLER_METHOD_META,
);
expect(authMetadata).to.be.undefined();
});
async function givenRequestContext() {
const app = new Application();
app.component(RestComponent);
const server = await app.getServer(RestServer);
const requestContext = new Context(server);
requestContext.bind(RestBindings.Http.CONTEXT).to(requestContext);
return requestContext;
}
});
before(function() {
ds = new juggler.DataSource({
name: 'db',
connector: MockConnector,
});
ctx = new Context();
ctx.bind('datasources.googleMap').to(ds);
ctx.bind('controllers.MyController').toClass(MyController);
});
function givenRequestContext() {
app = new Application();
reqCtx = new Context(app);
reqCtx
.bind(SecurityBindings.USER)
.to({[securityId]: 'user-01', name: 'user-01'});
controller = new OrderController();
}
export async function main() {
const ctx = new Context('invocation-context');
ctx.bind(CURRENT_USER).to('John');
ctx.bind('greeter').toClass(Greeter);
const greeter = await ctx.get('greeter');
console.log(greeter.hello());
}
export async function main() {
const ctx = new Context();
ctx.bind('name1').to('John');
ctx.bind('name2').to('Jane');
const class1 = createClassWithDecoration('name1', {tags: {prefix: '1'}});
const binding1 = createBindingFromClass(class1, {key: 'greeter1'});
ctx.add(binding1);
console.log('1:', binding1.tagMap);
const class2 = createClassWithDecoration('name2', {tags: {prefix: '2'}});
const binding2 = createBindingFromClass(class2, {key: 'greeter2'});
ctx.add(binding2);
console.log('2:', binding2.tagMap);
const greeting1 = await ctx.get('greeter1');
console.log('1: %s', greeting1.hello());