I'm working on a ServiceStack-based project that has an MVC web app and some messaging/polling apps that run as Azure webjobs. The project uses the general structure recommended in this SO question, but I'm finding that some of my requirements don't fit particularly well.
Specifically, what is the recommended way to handle aggregates in models? For example, let's say I want to have a Statistics
model that looks something like this:
public class Statistics
{
public int TotalCompletedSessions { get; set; }
public int TotalAbandonedSessions { get; set; }
public int AverageSessionDuration { get; set; }
public int MaxSessionDuration { get; set; }
}
This is a simplistic example, but would I be better off to create a StatisticsRequest
class that would return a StatisticsResponse
DTO, with my service interface using OrmLite to pull a query that would return the aggregates? Or should I just have the service be super-RESTful and focus on delivering only resources (in the example above, full Session
objects) and calculate those aggregates using some sort of business logic layer?
If the latter, where should that business logic exist, and could/should it be available to external clients?