Status: Current. Where this is implemented names the code and the build targets.
Use this guide to start an application in a repository of its own. It assumes Domains, which explains how an application extends Core and includes its source.
The starting point is the sample application in the platform’s repository. It includes the model, the database layers, a command-line tool, a server, a .NET workspace and their tests. The platform’s CI generates, builds and tests the sample for every pull request that changes more than the documentation, so the sample follows the platform.
To copy, generate and test the application, you need Git, the .NET 10 SDK and a POSIX shell with Perl. The optional sign-in walkthrough uses PowerShell and SQL Server LocalDB on Windows.
1. Create the repository and add the platform
Section titled “1. Create the repository and add the platform”An application compiles the source of the platform, so it keeps a copy of the platform’s repository next to its own projects. A Git submodule holds that copy:
mkdir my-appcd my-appgit initgit submodule add https://github.com/allors/allors3.git allorsThe build computes the version of the platform’s projects from the history of that copy, and
stops in a shallow one. Give CI the full history as well: with GitHub’s checkout action, set
fetch-depth: 0 next to submodules: true. Issue
#409 records the details.
2. Copy the sample’s projects
Section titled “2. Copy the sample’s projects”cp -R allors/sample/Repository allors/sample/Database allors/sample/Workspace .| Project | What it holds |
|---|---|
Repository/Domain | The model: Core’s, which the project includes, and the application’s own, in Custom. |
Database/Meta | The metadata, which a generator writes from the model. |
Database/Resources | The messages of the domain, merged from Core’s. |
Database/Domain | The domain: Core’s code, the calls to the hooks in Virtual, the application’s code in Custom, and the list of rules in Rules.cs. |
Database/Configuration | The services of the database. |
Database/Generate | The generator of the classes of the domain and of the workspace. |
Database/Commands | The command-line tool. |
Database/Server | The HTTP server that hosts Core’s sign-in endpoint and JSON API for the application’s domain. |
Database/Domain.Tests, Database/Commands.Tests and Database/Server.Tests | The tests of the domain, the tool and the HTTP API. |
Workspace/Meta and Workspace/Meta.Lazy | The metadata of the workspace Default, which the generator writes from the model. |
Workspace/Domain | The typed classes of the workspace, which the generator writes, and Core’s code for the workspace. |
Workspace/Configuration | The services of the workspace and of its sessions. |
Workspace/Tests | The tests of the workspace, on the Local and the Remote adapter. |
3. Point the projects at the submodule
Section titled “3. Point the projects at the submodule”In the platform’s repository the projects of the sample reach the platform’s source with paths
that start with ..\..\..\dotnet\. Next to the submodule those paths start with
..\..\allors\dotnet\. The generator in Database/Generate also names its templates with paths
that start with ../dotnet/, relative to the folder from which it runs. These commands change both:
grep -rl --include='*.csproj' '\.\.\\\.\.\\\.\.\\dotnet\\' Repository Database Workspace | xargs perl -pi -e 's/\.\.\\\.\.\\\.\.\\dotnet\\/..\\..\\allors\\dotnet\\/g'perl -pi -e 's#"\.\./dotnet/#"allors/dotnet/#' Database/Generate/Program.csThe projects then include Core with lines such as this one, from Database/Domain/Domain.csproj:
<Compile Include="..\..\allors\dotnet\Core\Database\Domain\Core*\**\*.cs" />4. Leave the build’s output out of Git
Section titled “4. Leave the build’s output out of Git”The build and the generators write to folders named bin, obj and Generated, which the
platform’s repository ignores. Ignore them in the application’s repository too:
printf '[Bb]in/\n[Oo]bj/\n[Gg]enerated/\n' > .gitignore5. Generate
Section titled “5. Generate”Generated code is not committed. Three tools write it; run them from the root of the application’s repository:
mkdir -p Database/Resources/Generateddotnet run --no-launch-profile --project allors/dotnet/Core/Database/Merge -- allors/dotnet/Core/Database/Resources/Core Database/Resources/Generateddotnet run --no-launch-profile --project allors/dotnet/System/Repository/Generate -- Repository/Domain/Repository.csproj allors/dotnet/System/Repository/Templates/meta.cs.stg Database/Meta/Generateddotnet run --project Database/Generate--no-launch-profile keeps dotnet run from reading the launch settings that the two projects of
the platform hold for their own development.
- Merge writes Core’s messages to
Database/Resources/Generated. The folder has to exist: without it, Merge exits with code 1 and prints nothing. An application with messages of its own passes their folder as well: every argument but the last is a folder to read. - The repository generator reads the model and writes the metadata to
Database/Meta/Generated. - The application’s generator writes the classes of the domain to
Database/Domain/Generated, and the metadata and the typed classes of the workspaceDefaulttoWorkspace/Meta/Generated,Workspace/Meta.Lazy/GeneratedandWorkspace/Domain/Generated.
Generate again after every change to the model. In the platform’s repository the targets
SampleMerge and SampleGenerate of the build run the same tools on the sample.
6. Build and test
Section titled “6. Build and test”The command-line tool and the server read their settings from one file below the
configuration root, and stop without it; so do the
tests that run them. Create a configuration root for development in the application’s repository,
on the Snapshot adapter, which needs no database server, and point ALLORS_CONFIG_ROOT at it:
mkdir -p config/customprintf '{\n "adapter": "snapshot"\n}\n' > config/custom/appsettings.jsonexport ALLORS_CONFIG_ROOT="$PWD/config"custom is the name that the sample’s tool and server pass to AddAllorsConfiguration. Then
build and run the tests:
dotnet test Database/Domain.Testsdotnet test Database/Commands.Testsdotnet test Database/Server.Testsdotnet test Workspace/TestsThe domain tests use the Memory adapter, unless ALLORS_TEST_ADAPTER names another:
Test on PostgreSQL or SQL Server runs them on a database
server. The command-line and server tests use Snapshot. The
server tests start the application in the test process and send HTTP requests to it. The
workspace tests run each test on the Local and on the Remote adapter, with the database on
Snapshot and, for the Remote adapter, the server in the test process. By default, all four suites
run without a database server.
Run the server and sign in
Section titled “Run the server and sign in”The tool that creates the user and the server that signs the user in must share a database. This example uses PowerShell 7.2 or later and SQL Server LocalDB on Windows. Run it from the application root after generating the model. For SQL Server or PostgreSQL elsewhere, set the adapter, application connection and admin connection for that server as described in Configuration; Host a server gives the steps from bash.
Choose a fresh database for this walkthrough. init drops and recreates the named database,
and populate replaces its contents. The following commands name the configuration root of this
step for the terminal, override its adapter and connection with environment variables, choose a
new database name, populate the sample’s user groups and create a member of Workers. Enter a
password when the tool prompts.
$env:ALLORS_CONFIG_ROOT = "$PWD\config"$database = "allors_sample_" + [guid]::NewGuid().ToString("N")$instance = 'Server=(localdb)\MSSQLLocalDB;Integrated Security=true;TrustServerCertificate=true'$env:adapter = 'sqlclient'$env:ALLORS_SQLCLIENT = "$instance;Database=master"$env:ConnectionStrings__DefaultConnection = "$instance;Database=$database"
dotnet run --project Database/Commands -- initdotnet run --project Database/Commands -- populatedotnet run --project Database/Commands -- user --name worker@example.com --group WorkersIn the same terminal, generate a signing key for this local run and start the server. Leave it running while you use the second terminal.
$env:JwtToken__Key = [Convert]::ToHexString([Security.Cryptography.RandomNumberGenerator]::GetBytes(32))dotnet run --no-launch-profile --project Database/Server -- --urls http://localhost:5080Open a second PowerShell terminal. Sign in with the password you entered for the worker, then
use the returned bearer token to sync the worker’s own Person. The sign-in response holds
the id of the user in u and the token in t. The sync request takes a list of numeric object
ids.
$api = 'http://localhost:5080/allors'$credentials = @{ l = 'worker@example.com' p = Read-Host 'Worker password' -MaskInput}$login = Invoke-RestMethod -Method Post -Uri "$api/Authentication/Token" ` -ContentType 'application/json' -Body ($credentials | ConvertTo-Json)if (-not $login.a) { throw 'Sign-in failed. Check the worker name and password.' }
$headers = @{ Authorization = "Bearer $($login.t)" }$body = @{ o = @([long]$login.u) } | ConvertTo-Json$sync = Invoke-RestMethod -Method Post -Uri "$api/sync" -Headers $headers ` -ContentType 'application/json' -Body $body$sync.o | Select-Object -ExpandProperty iThe printed id should match $login.u. A missing or invalid bearer token on /allors/sync
returns HTTP 401. Stop the server with Ctrl+C in its terminal. To accept another host name,
include it in the server’s AllowedHosts setting.
7. Make the domain your own
Section titled “7. Make the domain your own”Change the sample into the application one part at a time, and generate, build and test after each change:
- The domain. Give the domain an id of its own: the
[Domain]attribute of the structCustom, inRepository/Domain/Custom/Custom.cs, holds the sample’s. - The model. Replace
WorkItem, and the roles that the sample adds toPerson, with the classes of the application, each with ids of its own; The model describes the declarations. The users of an application are objects of a class that implements Core’s interfaceUser, asPersondoes. - The rules.
Database/Domain/Rules.cslists Core’s six rules and the application’s own; Write a rule shows how to add one. - The setup and the security. The folder
Database/Domain/Customholds the sample’s setup, security and upgrade. Grant access and Upgrade a population explain them. - The workspace.
[Workspace]on the declarations of the model decides which classes, roles and methods a client can use; Use a workspace shows how to connect, pull and push. - The tests. Replace the tests of the sample with the application’s.
Files that follow the platform
Section titled “Files that follow the platform”Core’s code needs classes and members that the platform keeps outside its folders Core, most of
them in the folders of its test domain, so an application does not include them. The sample has
its own versions of them, and an application keeps these:
| Files | What the application does with them |
|---|---|
Database/DatabaseServices.cs, Database/DefaultDatabaseServices.cs, Database/PreparedFetches/PreparedSelects.cs and Transaction/TransactionServices.cs, below Database/Configuration/Custom | Keeps them as the platform has them. |
The three files in Database/Domain/Virtual, and Database/Domain/Custom/ObjectsBase.cs | Keeps them as the platform has them while its domain extends Core directly. With domains in between, the files in Virtual call the part of each domain, as Domains explains. |
Database/PreparedExtents/PreparedExtents.cs and Database/WorkspaceMask/WorkspaceMask.cs, below Database/Configuration/Custom | Adds entries of its own; the sample’s are empty. |
Database/Meta/Custom/MetaBuilder.cs | Keeps the method BuildCustom, which the generated metadata calls, and changes the metadata of its domain there when it needs to. |
Database/Domain/Rules.cs | Lists Core’s six rules next to its own. |
Database/Generate/Program.cs | Holds the paths of the templates and of their output, for the domain and for the workspace, relative to the folder from which the generator runs; step 3 points the templates at the submodule. |
Workspace/WorkspaceServices.cs and Session/SessionServices.cs, below Workspace/Configuration/Custom | Keeps them as the platform has them. |
Issue #408 records why an application needs these files.
Update the platform
Section titled “Update the platform”Move the submodule to the newest commit of the platform, then generate, build and test again:
git submodule update --remote allorsThe sample changes together with the platform, so compare the files that the application keeps as the platform has them with the sample’s, for example:
git diff --no-index allors/sample/Database/Domain/Virtual Database/Domain/VirtualCommit the new commit of the submodule together with the changes that it asks for.
Where this is implemented
Section titled “Where this is implemented”- The sample application is in
sample/. The targetsSampleMergeandSampleGenerateof the Nuke build, inbuild/Sample/Build.cs, run the platform’s tools on it, andSampleTestruns its tests. - Merge is in
dotnet/Core/Database/Merge, the repository generator indotnet/System/Repository/Generate, with its templatedotnet/System/Repository/Templates/meta.cs.stg, and the generator of Core’s domain, which the sample’s generator includes, indotnet/Core/Database/Generate, with the templatedotnet/Core/Database/Templates/domain.cs.stg. The sample’s generator also renders the templatesmeta.cs.stg,meta.lazy.cs.stganddomain.cs.stgofdotnet/Core/Workspace/Templates. - The projects of the workspace include
dotnet/Core/Workspace/Domain/Core*anddotnet/Core/Workspace/Configuration/Core*.SampleTestruns the tests ofsample/Workspace/Testsas well.