Add Vox to your application
Vox runs inside your own ASP.NET Core application. Reference the packages of the features the host has:
| Package | What it adds |
|---|---|
CommerceMind.Vox | Vox core: the model, the entity stores and the registration, builder.AddVox(...) |
CommerceMind.Vox.SqlServer, CommerceMind.Vox.Postgres or CommerceMind.Vox.Sqlite | Vox's and Nexus's databases, AddSqlServerStorage(), AddPostgresStorage() or AddSqliteStorage() |
CommerceMind.Vox.Processing | The background work of changes, imports and publications, AddProcessing() |
CommerceMind.Vox.Api | The Vox API, AddApi(), and the admin UI, AddAdminUI() |
CommerceMind.Vox.NexusAdmin | The Nexus admin, where imports and publications are monitored, AddNexusAdmin() |
CommerceMind.Vox.Images | Public image renditions, made with SkiaSharp, AddVoxImages(), see assets |
Program.cs says what the host does, and Vox does the wiring:
var builder = WebApplication.CreateBuilder(args);
var vox = builder.AddVox(options =>
{
options.ApplicationName = "Acme PIM";
options.UseAuthoring();
options.UseAssets(); // Vox:Assets:RootPath, or App_Data/assets
options.UseUsers<ApplicationUser>(); // the first administrator from Vox:Users
})
.AddSqlServerStorage() // ConnectionStrings:Vox, and optionally ConnectionStrings:Nexus
.AddProcessing() // this host runs Vox's background work
.AddVoxImages()
.AddApi()
.AddAdminUI()
.AddNexusAdmin();
builder.Services.AddResponseCompression(options => options.EnableForHttps = true);
var app = builder.Build();
app.UseResponseCompression();
app.MapVox();
await app.RunVoxAsync(args);
builder.AddVoxreads theVoxsection of the configuration, finds the entity types and the rest of the model's code in the application's assembly, and in any library you add, egoptions.EntityAssemblies.Add(typeof(Product).Assembly), registers Nexus with the queues and jobs of the features the host has, and builds Vox when the host is built.- The storage package connects Vox and Nexus to the database, and creates a missing database at startup. On SQL
Server and PostgreSQL, Nexus's tables share Vox's database unless
ConnectionStrings:Nexusnames another. On SQLite, Vox's database isApp_Data/vox.dbunlessConnectionStrings:Voxsays otherwise, and Nexus's is a file next to it,vox-nexus.db. app.MapVox()adds the middleware and endpoints of the registered features in the order they need, eg the admin UI at/vox/admin, the API at/vox/apiand the images at/images. Put the application's own middleware, eg CORS and compression, before it. An application that callsUseAuthentication()itself calls it beforeMapVox().app.RunVoxAsync(args)runs thevox migratecommands when the arguments ask for one, egdotnet MyApp.dll vox migrate --plan, and otherwise migrates the database to the model in code and serves, see one host.
The API package, CommerceMind.Vox.Api, brings the admin UI with it, so AddAdminUI needs no package of its own.
Compress the application's responses, so that the admin UI's model of the entity types, which is large for a big model, doesn't slow every start of the admin on a slow connection. See response compression.
RunVoxAsync only configures the applicationThe same Program.cs runs for vox migrate as for serving, so the code before RunVoxAsync doesn't start work or
touch the database. Work that prepares the database is an IVoxStartupInitializer, which runs at startup and during
vox migrate. Work that needs a started application, eg loading seed data through Nexus, registers on
app.Lifetime.ApplicationStarted.
Configuration
The Vox section of the configuration is read into the options before the callback of AddVox runs, so every option
has a key, and what the callback sets wins. Each feature reads its own part when it's added. The common keys:
| Key | |
|---|---|
ConnectionStrings:Vox | Vox's database. Required on SQL Server and PostgreSQL; App_Data/vox.db on SQLite |
ConnectionStrings:Nexus | Nexus's database. Without it, Nexus shares Vox's database, or on SQLite gets a file next to it |
Vox:ApplicationName | The name that the admin UI shows |
Vox:Users:InitialAdministratorEmail, Vox:Users:InitialAdministratorPassword | The first administrator, created when there's none, see the initial administrator |
Vox:Assets:RootPath | Where UseAssets() stores asset files, App_Data/assets by default |
Vox:Images:RenditionRootPath, Vox:Images:PublicBaseUrl | Where image renditions are stored, App_Data/renditions by default, and the CDN in front of them |
Vox:Assets:AzureBlob:ConnectionString, ServiceUri, ContainerName | The container of asset files with AddVoxAzureBlobAssets(), see Azure Blob Storage |
Vox:Images:AzureBlob:ConnectionString, ServiceUri, ContainerName | The container of image renditions with AddVoxAzureBlobRenditions(), the assets' container by default |
Vox:Deployment:DeploymentId, Vox:Deployment:ApiKey | The deployment and its key, see deployments |
Vox:Profiler:StartupDuration | Profiles the host's start, see profiling |
Relative paths are resolved against the application's content root. In an environment variable, a nested key uses
double underscores, eg Vox__Deployment__DeploymentId or ConnectionStrings__Vox. Keep secrets, such as the
administrator's password and the connection strings, out of committed files, see
security.
Vox reads these settings while Program.cs composes the host. A test that runs the application with
WebApplicationFactory therefore passes them with builder.UseSetting("ConnectionStrings:Vox", ...): settings added
with ConfigureAppConfiguration reach the application only after it has been composed, so Vox wouldn't see them.
In Development, Vox also accepts a well-known API key with full permissions, see local development.
Pooling=FalseVox processes the entities of a batch on parallel workers, which each open a connection at the same moment. The
connection pool of Microsoft.Data.Sqlite can then hand the same SQLite connection to two of them, which fails with
errors such as unable to delete/modify collation sequence due to active statements, and lets one worker's statements
run in the other's transaction. AddSqliteStorage() adds Pooling=False to Vox's connection string unless it sets
Pooling itself: don't turn the pool on for a SQLite database file, or process serially with
options.SerialProcessing = true. An in-memory database has no pool.
Routing
Routing is independently packageable. Reference CommerceMind.Vox.Routing,
CommerceMind.Vox.Routing.EntityFramework, and CommerceMind.Vox.Routing.Api, then register its sink, store, and
request integration:
vox.AddVoxRouting()
.AddEntityFrameworkRouting(options =>
options.ConfigureDbContext = (_, db) => db.UseSqlite(routesConnection))
.AddVoxRoutingApi(options => options.DefaultSpace = "storefront");
MapVox() serves the published routes at /content/{**path}; options.Pattern of AddVoxRoutingApi sets another
path. Use /{**path} only when Vox should own the application's root routes.
The bundled durable IVoxRouteStore implementation uses Entity Framework and SQL. Routing uses a dedicated database
context; point it at a durable provider and apply the routing schema as part of deployment. When Vox's database is
reset, reset the routing tables with it: a full route publication removes the routes of entities it no longer produces
through the publication journal in Vox's database, so routes left from before the reset would otherwise stay and point
at entities that are gone. Routing registers a scheduled assessment of duplicate URLs, so it needs the assessment
storage that the Entity Framework storage provides. High-traffic applications
may register exactly one custom IVoxRouteStore instead. An official Redis implementation is coming but is not yet
included.
Without a deployment id, the application is one deployment that writes and processes as soon as it starts, which is
what you want in development. To run a new release next to the old one and move the processing to it only when your
pipeline activates it (both releases accept writes the whole time), set Vox:Deployment:DeploymentId (a new value for
every deployment) and Vox:Deployment:ApiKey. The first administrator of a new installation is still created when the
first host starts. See deployments.