BaseMapping<M>.namedFactory constructor

const BaseMapping<M>.namedFactory(
  1. String name, [
  2. Object? configInstance
])

Creates a reference to a named factory function for creating mappers.

Use this constructor when you want to provide a factory function that creates mapper instances dynamically. This is particularly useful for libraries that need to coordinate mapping across multiple types with a single, shared configuration and strategy.

The factory function is called with the specific type information for this class, and optionally the configuration object if configInstance is specified. This allows a single factory to handle different classes while maintaining type safety.

When using this approach, you must:

  1. Implement a factory function with the appropriate signature
  2. Provide the factory function as a named parameter to initRdfMapper

This approach is ideal for:

  • Libraries that need to coordinate mapping across all stored types
  • Cases where a single authority needs to manage resource allocation

The name will appear as a parameter name in the generated initRdfMapper function. The optional configInstance specifies the configuration object instance that will be passed to the factory function and thus influences the type signature of the factory function.

Example:

// Configuration for pod coordination
const podConfig = PodConfig(storagePolicy: 'distributed');

// Used in annotation
@RdfGlobalResource(
  Document.classIri,
  IriStrategy.namedFactory('podIriFactory', podConfig)
)
class Document { /* ... */ }

// Factory function with type parameter and config:
IriTermMapper<(String,)> createPodIriMapper<T>(PodConfig config) {
  return PodIriMapper<(String,)>(
    targetType: T,
    storagePolicy: config.storagePolicy
  );
}

// Generated initRdfMapper calls: podIriFactory<Document>(podConfig)
final rdfMapper = initRdfMapper(
  podIriFactory: createPodIriMapper,
);

Implementation

const BaseMapping.namedFactory(String name, [Object? configInstance])
    : _mapperName = null,
      _mapperType = null,
      _mapperInstance = null,
      _factoryName = name,
      _factoryConfigInstance = configInstance;