Parties
A party is the person or organization a record belongs to: the owner of an asset, the customer of a work order. The same word "customer" has meant a user id in one module and a Customers record id in another, so records name parties with a kind and an id instead.
The contracts are in CrestApps.OrchardCore.Parties.Abstractions. There is no feature; the modules that keep parties register sources.
PartyRef
PartyRef { Kind, Id } is a value type. Kind is an open string; PartyKinds names the well-known ones:
| Kind | The id is | Source | Registered by |
|---|---|---|---|
User | An Orchard Core user id | UserPartySource (IUserSearchService, named by IDisplayNameProvider) | The CrestApps Users module, and Assets when OrchardCore.Users is on |
Customer | A Customers module customer record id | CustomerPartySource | Customers |
Account | An account content item id | AccountPartySource | Accounts |
Contact | A CRM contact content item id | Assets' contact source | Assets, when Omnichannel Management is on |
Guest | A guest's id | none yet |
PartyRef.ToString() writes Kind:Id, and PartyRef.TryParse reads it back.
Finding and naming parties
Inject IPartyDirectory (register it with services.AddPartyDirectory()):
Kindslists the kinds that have a source, andGetSource(kind)returns it (kinds compare without case; the first source registered for a kind answers).SearchAsync(kind, query, count)finds parties of a kind for a picker; each result is aPartyOption { Id, Name }.GetNameAsync(party)andGetNamesAsync(parties)name parties, with one lookup per kind.
Adding a kind of party
Implement IPartySource (Kind, SearchAsync, GetNamesAsync) in the module that keeps the records, or its .Core project, and register it:
services.AddPartySource<VendorPartySource>();
Consumers
- Assets reads an asset's owner through the party sources. The stored
AssetOwnerKindkeeps its values:Customerholds a user id and maps to theUserparty kind (AssetOwners.ToPartyKind,asset.ToParty()). - Work Orders picks and names a work order's customer, account and contact through
IPartyDirectory.WorkOrder.CustomerIdandServiceAgreement.CustomerIdkeep their stored name and hold a user id (party kindUser).