Skip to main content

Domain Composition

This page covers how to declare and compose Cognibase Domains at the assembly level.

Declaring a Domain

Every domain assembly must carry the [RuntimeDomain] assembly attribute. At a minimum you must supply the DomainName:

// AssemblyInfo.cs  (or any file that accepts assembly-level attributes)
[assembly: RuntimeDomain(DomainName = "MyApp.Domain")]

The DomainName is used as the domain identifier throughout the Cognibase runtime — in transactions, subscriptions, and log output. Choose a name that is stable across releases.

Key [RuntimeDomain] Options

OptionTypeDefaultDescription
DomainNamestringRequired. Logical name of this domain
DomainShortCodestring""Optional short abbreviation for the domain name
EntitiesNameSpacestring""Namespace prefix used when locating entity types
Descriptionstring""Human-readable description shown in admin tooling
DefaultIdPersistenceModeDataItemIdPersistenceModeKeyHow object identity is persisted by default across the domain
ClientCacheModeDomainCacheModeClassCaching strategy applied on the client side
ServerCacheModeDomainCacheModeClassCaching strategy applied on the server side
ClientPreLoadModeDomainPreLoadModeClassPre-load strategy applied on the client side
ServerPreLoadModeDomainPreLoadModeClassPre-load strategy applied on the server side
InitializationModeDomainInitializationModeInServerControls where domain initialization code runs
IsReportProviderbooltrueExposes the domain as a data source for reporting

Security Defaults

[RuntimeDomain] also carries a full set of security defaults that apply to every class and property in the domain unless overridden at a lower level:

OptionDefault
SecurityOnFieldsfalse
SecurityOnActionstrue
SecurityDefaultLoadAllowtrue
SecurityDefaultBrowseAllowtrue
SecurityDefaultDisplayAllowtrue
SecurityDefaultSaveNewAllowtrue
SecurityDefaultSaveUpdatedAllowtrue
SecurityDefaultSaveDeletedAllowtrue
SecurityDefaultFieldDisplayAllowtrue
SecurityDefaultFieldChangeAllowtrue
SecurityDefaultExecuteActionAllowtrue

Depending on Other Domains

A domain can reference classes from other domain assemblies. You declare those dependencies with [RequiredDomain] or [IncludedDomain], both placed at the assembly level. Both take the Type of the target domain's DataItemDomainFactory subclass as their argument.

[RequiredDomain]

Use [RequiredDomain] when your domain's data model cannot function without the referenced domain — for example, when one of your entity properties is typed to a class that lives in the other domain.

[assembly: RuntimeDomain(DomainName = "MyApp.Domain")]
[assembly: RequiredDomain(typeof(CommonDomainFactory))]

The Cognibase runtime will enforce that the required domain is loaded before your domain starts.

[IncludedDomain]

Use [IncludedDomain] for a looser reference where the dependency is optional or dynamically resolved:

[assembly: RuntimeDomain(DomainName = "MyApp.Domain")]
[assembly: IncludedDomain(typeof(TopologyDomainFactory))]

Example — Multi-Domain Assembly

The following example is modelled on the Is2Aware system, where separate domain assemblies cover generic/common data, topology, and application-specific data. Each domain assembly declares its own [RuntimeDomain] and then lists any assemblies it depends on:

// Missionware.Common.Generic.Domain — assembly-level declarations
[assembly: RuntimeDomain(DomainName = "Missionware.Common.Generic.Domain")]

// Missionware.Common.Topology.Domain — depends on the generic domain
[assembly: RuntimeDomain(DomainName = "Missionware.Common.Topology.Domain")]
[assembly: RequiredDomain(typeof(CommonGenericDomainFactory))]

// Missionware.Facility.Domain — depends on both common domains
[assembly: RuntimeDomain(DomainName = "Missionware.Facility.Domain")]
[assembly: RequiredDomain(typeof(CommonGenericDomainFactory))]
[assembly: RequiredDomain(typeof(TopologyDomainFactory))]

Domain Factory

Every domain must provide a DataItemDomainFactory subclass. The factory is the entry-point that the Cognibase Client Object Manager uses to register and initialise the domain at startup:

public class MyAppDomainFactory : DataItemDomainFactory
{
// Framework calls this to create instances of your DataItem classes
public override DataItem CreateDataItem(Type type) { ... }
}

The factory class is registered once during application bootstrapping:

// Client bootstrap
var client = ClientObjMgr.Initialize(cApp, ref clientSettings);
client.RegisterDomainFactory<MyAppDomainFactory>();

Serialization Alias

When serialized domain payloads must survive assembly renames or moves across deployment environments, attach a stable alias with [DataItemDomainSerializationAssemblyAlias]:

[assembly: DataItemDomainSerializationAssemblyAlias("MyApp.Domain.v1")]

This attribute maps the assembly to a stable string key used in serialized streams, so that an older client can still deserialize objects from a renamed assembly.