Resource
Resources are long-lived infrastructure clients like database pools, cache connections, API clients, or configuration objects.
Example
Section titled “Example”class Database extends Vla.Resource { static readonly unwrap = "db"
db = this.devStable("prisma", () => new PrismaClient())}
class UserRepo extends Vla.Repo { // Thanks to unwrap, this injects the 'db' property directly db = this.inject(Database)
async findAll() { return this.db.user.findMany() }}When to Use
Section titled “When to Use”- Database connections
- Cache clients
- Configuration singletons
Reference
Section titled “Reference”singleton - Single instance created and cached forever.
Properties
Section titled “Properties”static readonly scope = 'singleton'static readonly unwrap?: PropertyKeySpecial Property: unwrap
Section titled “Special Property: unwrap”The unwrap static property allows injectors to receive a specific property instead of the entire Resource instance.
class Database extends Vla.Resource { static readonly unwrap = "client"
client = new PrismaClient()}
class UserRepo extends Vla.Repo { // Injects the 'client' property directly, not the Database instance db = this.inject(Database)
async findAll() { return this.db.user.findMany() // this.db is PrismaClient }}Characteristics
Section titled “Characteristics”- Scope:
singleton(single instance forever) - Purpose: Database connections, cache clients, configuration
- Can inject: Other Resources, Contexts
- Best practices: Use for expensive-to-create resources; implement cleanup methods
Resources can be injected cross-module.