For as long as I can remember I have been using the classic 3 layer design pattern with Dependency Injection:
Presentation -> Service class -> Repository, and I always end up with the same problem: A few big Service classes that have way too much responsibility and code redundancy.
My mind have been poisoned by this design pattern after all these years, so I need a bit of advice to move on to something new. I have been doing some reading about other design patterns but there are so many choices and I fail to see the transition from my repository pattern to one of the many other patterns.
Basic example:
public void CreateMachine(Machine machine)
{
this.repository.Insert(machine);
}
public void StartMachine(Guid machineid)
{
Machine machine = repository.GetMachine(machineId);
machine.Started = true;
repository.UpdateMachine(machine);
MachineEvent mEvent = new MachineEvent(machineId);
mEvent.MachineId = machineId;
mEvent.EventType = MachineEventEnum.MachineStarted;
this.eventRepository.Insert(mEvent);
If (machine.IsBigMachine == true)
{
// Do something more
}
// many more objects to create or update...
}
The MachineService class will end up as a SuperService class, having the responsibility to create and update many different objects from my domain model. Because when something happens to an Machine object, then many other things need to happen. I usually have many more service classes but because of DI, I cant have a reference inbetween the service classes. That creates code redundancy. Any advice for a Repository pattern addict?
Aucun commentaire:
Enregistrer un commentaire