When to use
This service receives IValueMetadataList, sorts by descending priority, then selects the first implementation where applies(value) is true.
API Reference
The ValueMetadata service provides information about how rs-x should handle a value type at runtime: whether it should be proxied and whether it is async.
This service receives IValueMetadataList, sorts by descending priority, then selects the first implementation where applies(value) is true.
import { ValueMetadata } from '@rs-x/core';import {
InjectionContainer,
RsXCoreInjectionTokens,
RsXCoreModule,
type IValueMetadata,
} from '@rs-x/core';
await InjectionContainer.load(RsXCoreModule);
const valueMetadata = InjectionContainer.get<IValueMetadata>(
RsXCoreInjectionTokens.IValueMetadata,
);
console.log(valueMetadata.isAsync(Promise.resolve(1))); // true
console.log(valueMetadata.needsProxy(new Map())); // true
console.log(valueMetadata.needsProxy(42)); // false (fallback metadata)import { Inject, RsXCoreInjectionTokens, type IValueMetadata } from '@rs-x/core';
class MyConsumer {
constructor(
@Inject(RsXCoreInjectionTokens.IValueMetadata)
private readonly dependency: IValueMetadata,
) {}
}4 members in this class.
constructor(
@MultiInject(RsXCoreInjectionTokens.IValueMetadataList) valueMetadataList: readonly IValueMetadata[]
)Parameters
public applies(value: unknown): booleanParameters
Returns
boolean
public isAsync(value: unknown): booleanParameters
Returns
boolean
public needsProxy(value: unknown): booleanParameters
Returns
boolean