Replies: 1 comment 2 replies
-
So every case is going to be different and it's impossible to know all the context with the information provided. However, I can say that I was part of a team that did this, albeit a good few years ago now ~2016/2017 so my memory is somewhat faded. We migrated gradually from a traditional Controller, Service, Repository pattern/architecture to almost the entire application being based around MediatR requests and request handlers. As a general strategy, I would pick a public method on your service class and migrate this into a new Request RequestHandler e.g. You mention your services are dependent on additional services, in which case you have a couple of options:
It's difficult to know which would be the better option without knowing your full context, but I'd tend to prefer option 2, unless you can identify shared domain logic that is required for multiple handlers (Jimmy has a good talk and blog series on exactly this topic https://www.youtube.com/watch?v=f64tZ90Dntg) Over time, you will find you have extracted everything out of at least one service and all the logic is in request handlers, at which point you can delete the service. As mentioned, treat "Shared" services with caution and favour keeping everything in the handler, unless you can really identitfy shared behavior. There is always a cost with coupling... |
Beta Was this translation helpful? Give feedback.
-
Hi people, in my project I currently have a traditional N-Tier layer architecture where it goes like this
Request -> Controller -> Service -> DbContext
The Service is doing the most heavy lifting and most of the business logic goes in there. A typical service can inject other services required to perform the operation, it also does a lot of querying and writing of other entities as well. e.g
async Task ApproveReleaseProcess(...params){
var a = serviceA.Get(blah blah);
var b = serviceB.WriteToDb();
var c = serviceC.GetById(b.Id);
}
I am struggling to see how I can transition from this to leverage mediateR pattern. Hopefully the answer is not Do all the querying on the controller layer because I would like the controller to stay clean and minimal.
thanks
Beta Was this translation helpful? Give feedback.
All reactions