Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
/**
* A class with dependency injection
*/
class GreetingService {
// Constructor based injection
constructor(
// Inject a context view for all greeters
@inject.view(filterByTag('greeter'))
private greetersView: ContextView,
) {}
// Property based injection
@inject.getter(CURRENT_DATE)
private now: Getter;
async greet(
// Parameter injection
@inject('currentLanguage')
language: string,
// Parameter injection
@inject('currentUser')
userName: string,
) {
// Get current date
const date = await this.now();
// Get current list of greeters
const greeters = await this.greetersView.values();
for (const greeter of greeters) {
constructor(
// The provider is instantiated for Sequence constructor,
// at which time we don't have information about the current
// route yet. This information is needed to determine
// what auth strategy should be used.
// To solve this, we are injecting a getter function that will
// defer resolution of the strategy until authenticate() action
// is executed.
@inject.getter(AuthenticationBindings.STRATEGY)
readonly getStrategy: Getter,
@inject.setter(SecurityBindings.USER)
readonly setCurrentUser: Setter,
) {}
constructor(
// The provider is instantiated for Sequence constructor,
// at which time we don't have information about the current
// route yet. This information is needed to determine
// what auth strategy should be used.
// To solve this, we are injecting a getter function that will
// defer resolution of the strategy until authenticate() action
// is executed.
@inject.getter(AuthenticationBindings.STRATEGY)
readonly getStrategy: Getter,
@inject.setter(AuthenticationBindings.CURRENT_USER)
readonly setCurrentUser: Setter,
) {}
constructor(
@inject(AuthenticationBindings.METADATA)
public metadata: AuthenticationMetadata,
@inject(MyAuthBindings.USER_PERMISSIONS)
protected checkPermissons: UserPermissionsFn,
@inject.getter(AuthenticationBindings.CURRENT_USER)
public getCurrentUser: Getter,
) {}
constructor(
@inject.getter(AuthorizationBindings.METADATA)
private readonly getMetadata: Getter,
@inject(AuthorizationBindings.PATHS_TO_ALLOW_ALWAYS)
private readonly allowAlwaysPath: string[],
) {}
export function getter(nameOrClass: string | Class>) {
const name =
typeof nameOrClass === 'string' ? nameOrClass : nameOrClass.name;
return inject.getter(`repositories.${name}`);
}
}