BaseHost
provides an easy-to-use entry point for hosts of Fluid experiences. Given a configuration, it helps load and initialize a container and provides helpers to retrieve Fluid objects from that container.
To create a BaseHost
, you'll need to profide a configuration IBaseHostConfig
.
const baseHostConfig = {
codeResolver, // an IFluidCodeResolver
documentServiceFactory, // an IDocumentServiceFactory
urlResolver, // an IUrlResolver
};
const baseHost = new BaseHost(baseHostConfig);
The key members of IBaseHostConfig
are an IFluidCodeResolver
(used for loading code into the container), an IDocumentServiceFactory
(used for connecting to the Fluid service), and an IUrlResolver
(used for resolving URLs used in API calls against the Loader
and Container
).
BaseHost
provides a method .initializeContainer()
which will retrieve a Container
from the given url, and if necessary initializing it with the given code in the process.
const container = await baseHost.initializeContainer(url, codeDetails);
Once the container is retrieved and initialized this way, requests can be made against it.
BaseHost
also provides a method .requestFluidObject()
for retrieving Fluid objects directly (bypassing the Container
) for convenience.
const fluidObject = await baseHost.requestFluidObject(url);
The Loader
can be also be retrieved via .getLoader()
.
const loader = await baseHost.getLoader();
If the full facilities of a BaseHost
aren't needed, the helper initializeContainerCode()
can be used directly to initialize a container with code.
await initializeContainerCode(container, codeDetails);
After this promise resolves, the container will be initialized, though the context change may not have occurred yet.