Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('binds a server with a different scope than SINGLETON', async () => {
@bind({scope: BindingScope.TRANSIENT})
class TransientServer extends FakeServer {}
const binding = app.server(TransientServer);
expect(binding.scope).to.equal(BindingScope.TRANSIENT);
});
it('binds a controller', () => {
const binding = app.controller(MyController);
expect(Array.from(binding.tagNames)).to.containEql(CoreTags.CONTROLLER);
expect(binding.key).to.equal('controllers.MyController');
expect(binding.scope).to.equal(BindingScope.TRANSIENT);
expect(findKeysByTag(app, CoreTags.CONTROLLER)).to.containEql(
binding.key,
);
});
it('binds a transient component', () => {
@bind({scope: BindingScope.TRANSIENT})
class MyTransientComponent {}
const binding = app.component(MyTransientComponent);
expect(binding.scope).to.equal(BindingScope.TRANSIENT);
});
it('binds a server with a different scope than SINGLETON', async () => {
@bind({scope: BindingScope.TRANSIENT})
class TransientServer extends FakeServer {}
const binding = app.server(TransientServer);
expect(binding.scope).to.equal(BindingScope.TRANSIENT);
});
repository>(
repoClass: Class,
name?: string,
): Binding {
const binding = createBindingFromClass(repoClass, {
name,
namespace: 'repositories',
type: 'repository',
defaultScope: BindingScope.TRANSIENT,
});
this.add(binding);
return binding;
}
async load() {
await super.load();
this.interceptors = this.classes as InterceptorProviderClass[];
for (const interceptor of this.interceptors) {
debug('Bind interceptor: %s', interceptor.name);
const binding = createBindingFromClass(interceptor, {
defaultScope: BindingScope.TRANSIENT,
});
this.app.add(binding);
debug('Binding created for interceptor: %j', binding);
}
}
}
repository>(
repoClass: Class,
name?: string,
): Binding {
const binding = createBindingFromClass(repoClass, {
name,
namespace: 'repositories',
type: 'repository',
defaultScope: BindingScope.TRANSIENT,
});
this.add(binding);
return binding;
}
AuthenticationStrategy,
AUTHENTICATION_STRATEGY_NOT_FOUND,
} from '../types';
/**
* An authentication strategy provider responsible for
* resolving an authentication strategy by name.
*
* It declares an extension point to which all authentication strategy
* implementations must register themselves as extensions.
*
* @example `context.bind('authentication.strategy').toProvider(AuthenticationStrategyProvider)`
*/
@extensionPoint(
AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
{scope: BindingScope.TRANSIENT},
) //this needs to be transient, e.g. for request level context.
export class AuthenticationStrategyProvider
implements Provider {
constructor(
@extensions()
protected authenticationStrategies: Getter,
@inject(AuthenticationBindings.METADATA)
protected metadata?: AuthenticationMetadata,
) {}
async value(): Promise {
if (!this.metadata) {
return undefined;
}
const name = this.metadata.strategy;
const strategy = await this.findAuthenticationStrategy(name);
if (!strategy) {