Skip to content

Service

Services contain your business logic. They orchestrate between repositories, other services, and facades.

class UserService extends Vla.Service {
repo = this.inject(UserRepo)
billing = this.inject(BillingFacade)
session = this.inject(SessionService)
async getProfile(userId: string) {
// Authorization
const currentUser = await this.session.currentUser()
if (currentUser.id !== userId) {
throw new UnauthorizedError()
}
// Data fetching
const user = await this.repo.findById(userId)
const subscription = await this.billing.getSubscription(userId)
return {
...user,
hasSubscription: !!subscription
}
}
}
  • Business logic
  • Validation
  • Authorization
  • Orchestration

invoke - Shared within a request.

static readonly scope = 'invoke'

Services inherit the inject() method from the Injectable mixin.

  • Scope: invoke (shared within a request)
  • Purpose: Business logic, validation, authorization
  • Can inject: Other services (same module), Repos, Facades, Resources, Contexts
  • Best practices: Keep business logic here, not in repos or actions