AUA Framework Training — Episode 13

Business Services & Layer Architecture

Mastering Business Services, Entity Services, Generic Services, and Façade Design Patterns in AUA

Watch Video on YouTube

Services Layer Architecture

All business logic in AUA is implemented through services created within the service layer. Leveraging built-in repositories, developers are decoupled from manual repository wiring, allowing complete focus on core business requirements. Other services can be seamlessly injected and utilized where needed.

Business Services

Designed to implement medium to large-scale business logic cleanly. Acting similarly to the Façade design pattern, business services cover complex operations, prevent circular dependency injection, and vastly improve code maintainability.

Best Practice Recommendation: Consider a separate dedicated service for any significant business module to keep the architecture clean and decoupled.

Generic Services

Utilized for cross-cutting or generic utility tasks across the project, such as generating security access tokens. While not tied to a single domain entity, these services are essential components required throughout the application infrastructure.

Flexibility: Supports combining different types of services seamlessly for auxiliary tasks.

1. Business Service Implementation (Façade Pattern)

StudentBusinessService.cs

Business Services aggregate multiple Entity Services to implement complex business workflows. Inheriting from BaseBusinessService provides unified access to unit-of-work patterns without circular dependency risks.

public interface IStudentBusinessService : IBaseBusinessService
{
    Task RegisterStudentWithCoursesAsync(StudentRegisterVm model);
}

public class StudentBusinessService : BaseBusinessService, IStudentBusinessService
{
    private readonly IStudentService _studentService;
    private readonly ICourseService _courseService;

    public StudentBusinessService(
        IUnitOfWork unitOfWork,
        IStudentService studentService,
        ICourseService courseService) : base(unitOfWork)
    {
        _studentService = studentService;
        _courseService = courseService;
    }

    public async Task RegisterStudentWithCoursesAsync(StudentRegisterVm model)
    {
        // 1. Insert Student via Entity Service
        var studentId = await _studentService.InsertAsync(model.StudentDto);

        // 2. Assign Selected Courses
        await _courseService.AssignCoursesToStudentAsync(studentId, model.CourseIds);
    }
}

2. Cross-Cutting Generic Service Pattern

AccessTokenProviderService.cs

Generic services handle infrastructure operations (e.g., token creation, encryption, file handlers) independent of specific domain entities.

public interface IAccessTokenProviderService : IBaseGenericService
{
    string GenerateUserToken(long userId, string userName);
}

public class AccessTokenProviderService : BaseGenericService, IAccessTokenProviderService
{
    public string GenerateUserToken(long userId, string userName)
    {
        // Token generation logic using security provider
        return JwtSecurityHelper.CreateAccessToken(userId, userName);
    }
}
“
”
"If you think good architecture is expensive, try bad architecture."
AUA Framework Philosophy

Official Channels & Community

Connect with the AUA Framework ecosystem.