Reputation: 16677
I am finishing up a rewrite of a project management tool using ASP.NET MVC, LINQ2QL and the Repository design pattern. Pretty much following the NerdDinner example.
I have a class called Task that has a child list of TaskStages. For sake of this example the Stages are Ready, Under Development and Completed. I keep track of the current Stage on the Task, but everytime the Stage changes I want to write a historical record to the Task Stage table.
I'm struggling on where to put this functionality and maintain testability. Does it go in the Controller? Repository? or the partial class?
If this is a design issue, please let me know!
Upvotes: 1
Views: 291
Reputation: 24088
...everytime the Stage changes I want to write a historical record to the Task Stage table.
You need to have a service that is responsible for changing Stage:
public interface IStageChanger {
void Rename(Task t, string newName);
// etc
}
I'm struggling on where to put this functionality and maintain testability. Does it go in the Controller? Repository? or the partial class?
Neither. Service level. You can have another service responsible for writing the history, so the resulting implementation of IStageChanger would be similar to this:
public class StageChanger : IStageChanger {
public StageChanger(ITaskHistoryWriter historyWriter) {
//
}
public void Rename(Task t,string newName) {
history.Write(t, /*whatever*/)
}
}
Then you using DependencyInjection container (Windsor or similar) just request your changer service.
Upvotes: 2
Reputation: 10782
I'm new to ASP.NET MVC but I would have a method on the class for changing stages and put the logic for tracking these changes within that method (refactoring as necessary). In short, I don't think this belongs explicitly in the controller.
Upvotes: 0
Reputation: 245399
You could handle this one of two ways.
Personally, I would create business objects that sat between the Controller and the Data Access (Repository/LINQ2SQL). You would then use those Objects as your Model and interact with the data through them.
You could also put the logic in the Controller...but then you have to repeat that logic across the board if there's more than one area of the application that needs to perform the same way.
Upvotes: 2