Repository navigation
domain services
There may be occasions when some domain logic needs to exist, but may not 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.ModelTypes.Services;
public class OrderDiscountDomainService : IDomainService //👈
{
public decimal CalculateTieredDiscount(Customer customer, Order order)
{
// Business Rule: VIP customers with orders over $100 get 15%,
// high-tier loyalty members get an additional 5%.
if (!customer.IsVip || order.TotalAmount < 100.00m)
{
return 0.00m;
}
decimal baseDiscount = order.TotalAmount * 0.15m;
if (customer.LoyaltyTier == LoyaltyTier.Gold)
{
baseDiscount += order.TotalAmount * 0.05m;
}
return baseDiscount;
}
}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.
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.
You will often have to use external resources as part of your business logic. These operations should NOT be part of your core domain model. Instead, use an Application Service instead.
Copyright © 2022-2026 Envivo Software
-
Objects
-
Configuring your Model
-
Testing your model
-
Other features