Documents injecute 1.x · Migrating from 0.x
Skip to content

Function: createProxyAccessor() ​

createProxyAccessor<C, Keys>(container, options?): Keys extends readonly unknown[] ? ProxyAccessor<ContainerServices<C>, Keys> : { readonly [K in string | number | symbol]: ServiceType<ContainerServices<C>, K> }

Defined in: src/utils/proxy.ts:44

Creates an object whose properties resolve container services on access. Use it to expose a container as a plain service object, optionally only some keys and under other names. The object is read-only; Object.keys(), in and spreading work.

Type Parameters ​

C ​

C extends ServiceProvider<{ }>

Keys ​

Keys extends readonly KeySpec<ContainerServices<C>>[] | undefined = undefined

Parameters ​

container ​

C

options? ​

ProxyAccessorOptions<Keys>

Returns ​

Keys extends readonly unknown[] ? ProxyAccessor<ContainerServices<C>, Keys> : { readonly [K in string | number | symbol]: ServiceType<ContainerServices<C>, K> }

Example ​

ts
const billing = createProxyAccessor(app, {
  keys: ['invoices', ['createInvoiceHandler', 'createInvoice']],
});
billing.invoices;      // resolves 'invoices'
billing.createInvoice; // resolves 'createInvoiceHandler'

Released under the MIT License.