jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11.14k stars 1.18k forks source link

Calling handlers from handlers, refactoring handlers #197

Closed jsodeman closed 7 years ago

jsodeman commented 7 years ago

As I'm getting further in CQRS using Mediatr I've started to run into situations where I'll need to make a calls to several handlers to process a Web API method and I'm not sure what they best approach is to doing this.

When calling one handler from another is it better to create an instance of the sub-handler directly, or to have a Mediatr instance in the handler to do it? Or, is this a bad pattern and should I only call handlers from the API Controller?

This is mostly coming from refactoring out duplicate code that's used by multiple handler, like a GetUserRolesHandler that would be used in multiple handlers for validating and building the data used to perform their actions.

KeithBarrows commented 7 years ago

Maybe investigate MediatR pipelines?

Tackling cross-cutting concerns with a mediator pipeline