Factory classes for creating and managing container runtimes that host and coordinate multiple data objects within Fluid containers. These factories provide the infrastructure for bootstrapping Fluid applications and managing the container lifecycle.
The foundational factory class for creating container runtimes with configurable data store registries, request handlers, and runtime options.
/**
* BaseContainerRuntimeFactory produces container runtimes with specified data store
* and service registries, request handlers, runtimeOptions, and entryPoint initialization.
* Can be subclassed to implement first-time initialization procedures.
*/
class BaseContainerRuntimeFactory
extends RuntimeFactoryHelper
implements IProvideFluidDataStoreRegistryKey Properties:
/** Data store registry for resolving factory types */
public get IFluidDataStoreRegistry(): IFluidDataStoreRegistry;Core Methods:
/**
* Creates a new container runtime instance
* @param context - Container context from the Fluid loader
* @param existing - Whether loading from existing container
* @returns Promise resolving to the runtime instance
*/
public async instantiateRuntime(
context: IContainerContext,
existing: boolean
): Promise<IRuntime>;
/**
* Called only the first time a container is created. Override to implement
* custom initialization logic such as creating default data stores.
* @param runtime - The newly created container runtime
*/
protected async containerInitializingFirstTime(runtime: IContainerRuntime): Promise<void>;Constructor:
public constructor(props: BaseContainerRuntimeFactoryProps);Usage Example:
class CustomContainerRuntimeFactory extends BaseContainerRuntimeFactory {
constructor() {
super({
registryEntries: [
myDataObjectFactory.registryEntry,
anotherFactory.registryEntry,
],
provideEntryPoint: async (runtime) => {
const handle = await runtime.getAliasedDataStoreEntryPoint("main");
return handle?.get() ?? Promise.reject("No main data store");
},
runtimeOptions: {
summaryOptions: { generateSummaries: true },
},
});
}
protected async containerInitializingFirstTime(runtime: IContainerRuntime) {
// Create and alias the main data store
const dataStore = await runtime.createDataStore("my-data-object");
await dataStore.trySetAlias("main");
}
}
export const fluidExport = new CustomContainerRuntimeFactory();A specialized container runtime factory that automatically creates and manages a single default data store, simplifying the most common Fluid application pattern.
/**
* A ContainerRuntimeFactory that initializes Containers with a single default data store,
* which can be requested from the container with an empty URL.
* This factory should be exposed as fluidExport off the entry point to your module.
*/
class ContainerRuntimeFactoryWithDefaultDataStore extends BaseContainerRuntimeFactoryStatic Properties:
/** The standard identifier used for the default data store */
public static readonly defaultDataStoreId: string;Key Properties:
/** The factory used to create the default data store */
protected readonly defaultFactory: IFluidDataStoreFactory;Constructor:
public constructor(props: ContainerRuntimeFactoryWithDefaultDataStoreProps);Automatic Initialization:
/**
* Automatically creates and aliases the default data store during first-time initialization
* @param runtime - The container runtime
*/
protected async containerInitializingFirstTime(runtime: IContainerRuntime): Promise<void>;Usage Example:
import { DataObject, DataObjectFactory, ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqueduct";
class AppDataObject extends DataObject {
// Your application logic here
}
const AppFactory = new DataObjectFactory({
type: "app",
ctor: AppDataObject,
});
// Simple container setup with default data store
export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore({
defaultFactory: AppFactory,
registryEntries: [AppFactory.registryEntry],
});/**
* Construction properties for BaseContainerRuntimeFactory
*/
interface BaseContainerRuntimeFactoryProps {
/** The data store registry for containers produced */
registryEntries: NamedFluidDataStoreRegistryEntries;
/**
* @deprecated Will be removed in a future release
* Dependency container for service injection
*/
dependencyContainer?: IFluidDependencySynthesizer;
/**
* @deprecated Will be removed once Loader LTS version is "2.0.0-internal.7.0.0"
* Request handlers for containers produced. Migrate to entryPoint pattern.
*/
requestHandlers?: RuntimeRequestHandler[];
/** The runtime options passed to the ContainerRuntime when instantiating */
runtimeOptions?: IContainerRuntimeOptions;
/** Function that initializes the entryPoint of ContainerRuntime instances */
provideEntryPoint: (runtime: IContainerRuntime) => Promise<FluidObject>;
/**
* The minVersionForCollab passed to the ContainerRuntime when instantiating.
* Controls collaboration compatibility requirements.
*/
minVersionForCollab?: MinimumVersionForCollab | undefined;
}/**
* Construction properties for ContainerRuntimeFactoryWithDefaultDataStore
*/
interface ContainerRuntimeFactoryWithDefaultDataStoreProps {
/** Factory for creating the default data store */
defaultFactory: IFluidDataStoreFactory;
/** The data store registry for containers produced */
registryEntries: NamedFluidDataStoreRegistryEntries;
/**
* @deprecated Will be removed in a future release
* Dependency container for service injection
*/
dependencyContainer?: IFluidDependencySynthesizer;
/**
* @deprecated Will be removed once Loader LTS version is "2.0.0-internal.7.0.0"
* Request handlers for containers produced. Migrate to entryPoint pattern.
*/
requestHandlers?: RuntimeRequestHandler[];
/** The runtime options passed to the IContainerRuntime when instantiating */
runtimeOptions?: IContainerRuntimeOptions;
/**
* Optional function that initializes the entryPoint of IContainerRuntime instances.
* Defaults to returning the default data store.
*/
provideEntryPoint?: (runtime: IContainerRuntime) => Promise<FluidObject>;
}const factory1 = new DataObjectFactory({ type: "type1", ctor: DataObject1 });
const factory2 = new DataObjectFactory({ type: "type2", ctor: DataObject2 });
class AppContainerRuntimeFactory extends BaseContainerRuntimeFactory {
constructor() {
super({
registryEntries: [
factory1.registryEntry,
factory2.registryEntry,
],
provideEntryPoint: async (runtime) => {
// Return a coordinator object that manages multiple data stores
const handle = await runtime.getAliasedDataStoreEntryPoint("coordinator");
return handle?.get() ?? Promise.reject("No coordinator");
},
});
}
protected async containerInitializingFirstTime(runtime: IContainerRuntime) {
// Create multiple data stores
const coordinator = await runtime.createDataStore("type1");
await coordinator.trySetAlias("coordinator");
const worker = await runtime.createDataStore("type2");
await worker.trySetAlias("worker");
}
}export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore({
defaultFactory: MyFactory,
registryEntries: [MyFactory.registryEntry],
runtimeOptions: {
// Summary configuration
summaryOptions: {
generateSummaries: true,
maxIdleTime: 5000,
},
// Garbage collection settings
gcOptions: {
gcAllowed: true,
sessionExpiryTimeoutMs: 60000,
},
// Compression settings
compressionOptions: {
minimumBatchSizeInBytes: 614400,
},
},
});export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore({
defaultFactory: MyFactory,
registryEntries: [MyFactory.registryEntry],
provideEntryPoint: async (runtime) => {
// Custom logic to determine which data store to return as entry point
const handle = await runtime.getAliasedDataStoreEntryPoint("default");
if (handle) {
const dataObject = await handle.get();
// Wrap or modify the data object before returning
return new EntryPointWrapper(dataObject);
}
throw new Error("Default data store not found");
},
});const customRequestHandler: RuntimeRequestHandler = async (request, runtime) => {
// Handle custom URL patterns
if (request.url.startsWith("/api/")) {
return {
mimeType: "application/json",
status: 200,
value: { message: "Custom API response" },
};
}
return undefined; // Continue to next handler
};
export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore({
defaultFactory: MyFactory,
registryEntries: [MyFactory.registryEntry],
requestHandlers: [customRequestHandler], // Deprecated pattern
});