-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72216eb
commit ab3b8d1
Showing
9 changed files
with
412 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/third-party.mediatr/src/mediatr/IPipelineBehavior.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type RequestHandlerDelegate<TResponse> = () => Promise<TResponse>; | ||
|
||
// https://github.com/jbogard/MediatR/blob/e611b1bcc00b10244810abeea2f7c62f155beb5e/src/MediatR/IPipelineBehavior.cs#L20 | ||
export interface IPipelineBehavior<TRequest, TResponse> { | ||
handle( | ||
request: TRequest, | ||
next: RequestHandlerDelegate<TResponse>, | ||
): Promise<TResponse>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/third-party.mediatr/src/mediatr/pipeline/RequestPostProcessorBehavior.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
IPipelineBehavior, | ||
RequestHandlerDelegate, | ||
} from '../IPipelineBehavior'; | ||
|
||
// https://github.com/jbogard/MediatR/blob/e611b1bcc00b10244810abeea2f7c62f155beb5e/src/MediatR/Pipeline/RequestPostProcessorBehavior.cs#L12 | ||
/** | ||
* Behavior for executing all <see cref="IRequestPostProcessor{TRequest,TResponse}"/> instances after handling the request | ||
*/ | ||
export class RequestPostProcessorBehavior<TRequest, TResponse> | ||
implements IPipelineBehavior<TRequest, TResponse> | ||
{ | ||
handle( | ||
request: TRequest, | ||
next: RequestHandlerDelegate<TResponse>, | ||
): Promise<TResponse> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/third-party.mediatr/src/mediatr/pipeline/RequestPreProcessorBehavior.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
IPipelineBehavior, | ||
RequestHandlerDelegate, | ||
} from '../IPipelineBehavior'; | ||
|
||
// https://github.com/jbogard/MediatR/blob/e611b1bcc00b10244810abeea2f7c62f155beb5e/src/MediatR/Pipeline/RequestPreProcessorBehavior.cs#L12 | ||
/** | ||
* Behavior for executing all <see cref="IRequestPreProcessor{TRequest}"/> instances before handling a request | ||
*/ | ||
export class RequestPreProcessorBehavior<TRequest, TResponse> | ||
implements IPipelineBehavior<TRequest, TResponse> | ||
{ | ||
handle( | ||
request: TRequest, | ||
next: RequestHandlerDelegate<TResponse>, | ||
): Promise<TResponse> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/third-party.mediatr/src/mediatr/wrappers/RequestHandlerWrapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Ctor, IServiceProvider } from '@yohira/base'; | ||
import { | ||
getRequiredService, | ||
getServices, | ||
} from '@yohira/extensions.dependency-injection.abstractions'; | ||
|
||
import { IRequest } from '../../mediatr.contracts/IRequest'; | ||
import { | ||
IPipelineBehavior, | ||
RequestHandlerDelegate, | ||
} from '../IPipelineBehavior'; | ||
import { IRequestHandler } from '../IRequestHandler'; | ||
|
||
// https://github.com/jbogard/MediatR/blob/761fb0b1b420f5a8c2cb4a751617dce7ab9c3fe3/src/MediatR/Wrappers/RequestHandlerWrapper.cs#L9 | ||
export abstract class RequestHandlerBase { | ||
abstract handle( | ||
request: object, | ||
serviceProvider: IServiceProvider, | ||
): Promise<any /* TODO */>; | ||
} | ||
|
||
// https://github.com/jbogard/MediatR/blob/761fb0b1b420f5a8c2cb4a751617dce7ab9c3fe3/src/MediatR/Wrappers/RequestHandlerWrapper.cs#L15 | ||
export abstract class RequestHandlerWrapper< | ||
TResponse, | ||
> extends RequestHandlerBase { | ||
abstract handle( | ||
request: IRequest<TResponse>, | ||
serviceProvider: IServiceProvider, | ||
): Promise<TResponse>; | ||
} | ||
|
||
// https://github.com/jbogard/MediatR/blob/761fb0b1b420f5a8c2cb4a751617dce7ab9c3fe3/src/MediatR/Wrappers/RequestHandlerWrapper.cs#L27 | ||
export class RequestHandlerWrapperImpl< | ||
TRequest extends IRequest<TResponse>, | ||
TResponse, | ||
> extends RequestHandlerWrapper<TResponse> { | ||
constructor(private readonly requestCtor: Ctor<TRequest>) { | ||
super(); | ||
} | ||
|
||
handle( | ||
request: IRequest<TResponse>, | ||
serviceProvider: IServiceProvider, | ||
): Promise<TResponse> { | ||
const handler = (): Promise<TResponse> => | ||
getRequiredService<IRequestHandler<TRequest, TResponse>>( | ||
serviceProvider, | ||
Symbol.for(`IRequestHandler<${this.requestCtor.name}>`), | ||
).handle(request as TRequest); | ||
|
||
return getServices<IPipelineBehavior<TRequest, TResponse>>( | ||
serviceProvider, | ||
Symbol.for(`IPipelineBehavior<${this.requestCtor.name}>`), | ||
) | ||
.reverse() | ||
.reduce( | ||
(next, pipeline) => () => | ||
pipeline.handle(request as TRequest, next), | ||
handler as RequestHandlerDelegate<TResponse>, | ||
)(); | ||
} | ||
} |
Oops, something went wrong.