Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Nov 29, 2023
1 parent f89a9dc commit f991a62
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mediatr.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/pkg/errors"
)

// HandlerRegisterer for registering `RequestHandler` to mediatr registry, if handler implements this interface it will be registered automatically
type HandlerRegisterer interface {
RegisterHandler() error
}

// RequestHandlerFunc is a continuation for the next task to execute in the pipeline
type RequestHandlerFunc func(ctx context.Context) (interface{}, error)

Expand All @@ -20,6 +25,12 @@ type RequestHandler[TRequest any, TResponse any] interface {
Handle(ctx context.Context, request TRequest) (TResponse, error)
}

// RequestHandlerWithRegisterer for registering `RequestHandler` to mediatr registry and handling `RequestHandler`
type RequestHandlerWithRegisterer[TRequest any, TResponse any] interface {
HandlerRegisterer
RequestHandler[TRequest, TResponse]
}

type RequestHandlerFactory[TRequest any, TResponse any] func() RequestHandler[TRequest, TResponse]

type NotificationHandler[TNotification any] interface {
Expand Down Expand Up @@ -49,6 +60,11 @@ func registerRequestHandler[TRequest any, TResponse any](handler any) error {
return nil
}

// RegisterMarkedHandlers register all handlers that have implemented `HandlerRegisterer` for registering handlers.
func RegisterMarkedHandlers() {
// TODO: find all types that implement `HandlerRegisterer using reflection
}

// RegisterRequestHandler register the request handler to mediatr registry.
func RegisterRequestHandler[TRequest any, TResponse any](handler RequestHandler[TRequest, TResponse]) error {
return registerRequestHandler[TRequest, TResponse](handler)
Expand Down

0 comments on commit f991a62

Please sign in to comment.