Skip to content

PlatformAPI reference

Class HostBuilder

Namespace: MicroEngine.Hosting
Assembly: MicroEngine.Hosting.dll
Guide: Composing a game for every platform

The composition of one host, configured once by the game’s Configure entry point and reused by every host that runs it: the desktop launcher (Program.cs), the browser page, the Android and iOS apps and tests. The host fills its defaults first (its platforms, where content files are, where saves go), then calls the game’s Configure, which may replace any of them and adds what the game needs (the game itself, platforms of its own, engine services). Nothing here is process-wide: two hosts in one process (an editor, parallel tests) never share a composition.

C#
public sealed class HostBuilder

Inheritance

object ← HostBuilder

Examples

C#
public sealed class MainGame : Game
{
public static void Configure(HostBuilder host) => host.UseGame(() => new MainGame());
...
}

Remarks

The engine’s modules keep their own parts in Services; the game façade adds methods to choose the game and change the platform catalog and request (UseGame, Platforms, ConfigureRequest in MicroEngine.Core).

Constructors

HostBuilder(HostEnvironment, LaunchRequest)

A composition for one launch of request in environment.

C#
public HostBuilder(HostEnvironment environment, LaunchRequest request)

Parameters

environment HostEnvironment

request LaunchRequest

Exceptions

ArgumentNullException

An argument is null.

Properties

Content

Where the game’s content files come from when the game names no folder of its own; null (the default) for the Content folder next to the program. The desktop host sets a macOS bundle’s resources, the Android app the folder it unpacked its assets to, the iOS app its bundle’s folder. Any source works: a folder (FolderContentSource), a zip archive (ZipContentSource) or files a host lists and opens itself (ListedContentSource).

C#
public IContentSource? Content { get; set; }

Property Value

IContentSource?

EngineConfiguration

Changes applied to every engine this host composes, after the game’s own Game.Configure.

C#
public IReadOnlyList<Action<EngineBuilder>> EngineConfiguration { get; }

Property Value

IReadOnlyList<Action<EngineBuilder>>

Environment

What the host knows about its process: its kind, developer variables and output.

C#
public HostEnvironment Environment { get; }

Property Value

HostEnvironment

Kind

The kind of host composing (Kind).

C#
public HostKind Kind { get; }

Property Value

HostKind

Request

What this launch asked for (script, captures, platform, time…).

C#
public LaunchRequest Request { get; }

Property Value

LaunchRequest

Services

The composition’s own parts, by type: the engine’s modules keep theirs here; a game may add its own.

C#
public ServiceRegistry Services { get; }

Property Value

ServiceRegistry

Storage

The save medium for a game id, for games that ask the composition for it; null (the default) for the platform’s default (files in the user’s data folder, the page’s localStorage in browsers).

C#
public Func<string, IStorage>? Storage { get; set; }

Property Value

Func<string, IStorage>?

Methods

ConfigureEngine(Action<EngineBuilder>)

Adds a change to every engine this host composes (services, systems, settings), applied in the order added.

C#
public HostBuilder ConfigureEngine(Action<EngineBuilder> configure)

Parameters

configure Action<EngineBuilder>

Returns

HostBuilder

This builder, for chaining.