Skip to content

domain services

vijay@envivo edited this page Jun 14, 2024 · 9 revisions

Domain Services

There may be occasions when some domain logic needs to exist, but cannot be attributed to any specific domain object. This is where Domain Services come in – they are stateless and operate on domain objects.

To create one, implement the IDomainService interface like so:

using Envivo.Fresnel.DomainTypes.Interfaces;

/// <summary>
/// Used to send re-supply orders to Suppliers
/// </summary>
public class StockReplenishmentService : IDomainService //👈
{
    /// <summary>
    /// Identifies all low stock levels, and sends order emails to the relevant suppliers
    /// </summary>
    public void SendOrdersToSuppliers()
    {
        /// Domain logic goes here
        ...
    }
}

This service appears in the navigation panel, and the action appears as a sub-option:

Methods on Domain Services may also accept parameters and other dependencies. See the Methods section for more information.

Triggering Domain Services from Objects

Domain Services can keep code clean, by maintaining separation between the Object (data) and the operations (logic).

But when exploring domain concepts with people, it helps if the actions are visually linked directly to the domain Objects. You can see an example of this in the Methods with Dependencies section.

Clone this wiki locally