Repository navigation
application services
When business operations need access to external resources to fulfil an operation (via databases or APIs), you need an Application Service to orchestrate the logic:
To create an Application Service, implement the IApplicationService interface like so:
using Envivo.Fresnel.ModelTypes.Services;
public class OrderDiscountDomainService : IApplicationService //👈
public class ApplyOrderDiscountApplicationService
{
private readonly ICustomerRepository _orderRepo;
private readonly ICustomerRepository _customerRepo;
private readonly OrderDiscountDomainService _discountDomainService;
public ApplyOrderDiscountApplicationService(
IOrderRepository orderRepo,
ICustomerRepository customerRepo,
OrderDiscountDomainService discountDomainService)
{
_orderRepo = orderRepo;
_customerRepo = customerRepo;
_discountDomainService = discountDomainService;
}
public async Task ApplyDiscountAsync(Order order)
{
// 1. Fetch data from DB (Async I/O)
Customer customer = await _customerRepo.GetByIdAsync(order.CustomerId);
// 2. Delegate to Pure Domain Service (Sync / Memory)
decimal discountAmount = _discountDomainService.CalculateTieredDiscount(customer, order);
// 3. Mutate Entity state (Sync / Memory)
order.ApplyDiscount(discountAmount);
// 4. Save state back to DB (Async I/O)
await _orderRepo.SaveAsync(order);
}
}This service appears in the navigation panel, and the action appears as a sub-option:

Methods on Application Services may also accept parameters and other dependencies. See the Methods section for more information.
When any Application Service has a method that accepts a Domain Object, that method will appear directly on the object itself:

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
.
using Envivo.Fresnel.ModelTypes.Services;
/// <summary>
/// Used to send re-supply orders to a Supplier
/// </summary>
public class StockReplenishmentService : IDomainService<Supplier> //👈
{
/// <summary>
/// Identifies all low stock levels, and sends order emails to the given supplier
/// </summary>
public Task SendOrdersToSupplierAsync(Supplier supplier)
{
/// Async Domain logic goes here
...
}
}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.
Copyright © 2022-2026 Envivo Software
-
Objects
-
Configuring your Model
-
Testing your model
-
Other features