The three levels of tenancy that Marten supports are expressed in the enum
TenancyStyle with effective values of:
Single, no multi-tenancy
Conjoined, multi-tenancy through tenant id
Separate, multi-tenancy through separate databases or schemas
Tenancy can be configured at the store level, applying to all documents or, at most fine-graned level, on individual documents.
Tenancy Through Policies
Tenancy can be configured through Document Policies, accesible via
StoreOptions.Policies. The following sample demonstrates setting the default tenancy to
TenancyStyle.Conjoined for all documents.
storeOptions.Policies.AllDocumentsAreMultiTenanted(); // Shorthand for // storeOptions.Policies.ForAllDocuments(_ => _.TenancyStyle = TenancyStyle.Conjoined);
Tenancy At Document Level & Policy Overrides
Tenancy can be configured at a document level through document mappings. This also enables overriding store-level configurations applied through Document Policies. The following sample demonstrates setting, through
StoreOptions the tenancy for
TenancyStyle.Conjoined, making it deviate from the configured default policy of
storeOptions.Policies.ForAllDocuments(x => x.TenancyStyle = TenancyStyle.Single); storeOptions.Schema.For<Target>().MultiTenanted();