Service
Services contain your business logic. They orchestrate between repositories, other services, and facades.
Example
Section titled “Example”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 } }}When to Use
Section titled “When to Use”- Business logic
- Validation
- Authorization
- Orchestration
Reference
Section titled “Reference”invoke - Shared within a request.
Properties
Section titled “Properties”static readonly scope = 'invoke'Methods
Section titled “Methods”Services inherit the inject() method from the Injectable mixin.
Characteristics
Section titled “Characteristics”- 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