Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
Errores de MediatR IPipelineBehavior<TRequest, TResponse> porque el tipo 'TRequest' no se puede usar como parámetro de tipo 'TRequest' en el tipo o método genérico

Estoy usando MediatR para hacer Solicitud - Registro de respuesta en mi aplicación usando IPipelineBehavior<TRequest, TResponse>

Ejemplo de código:

 internal sealed class AppLoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> { private readonly ILogger<AppLoggingBehavior<TRequest, TResponse>> _logger; public AppLoggingBehavior(ILogger<AppLoggingBehavior<TRequest, TResponse>> logger) { _logger = logger; } public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) { string requestName = typeof(TRequest).Name; string unqiueId = Guid.NewGuid().ToString(); string requestJson = JsonSerializer.Serialize(request); _logger.LogInformation($"Begin Request Id:{unqiueId}, request name:{requestName}, request json:{requestJson}"); var timer = new Stopwatch(); timer.Start(); var response = await next(); timer.Stop(); _logger.LogInformation($"End Request Id:{unqiueId}, request name:{requestName}, total request time:{timer.ElapsedMilliseconds}ms"); return response; } }

Pero después de actualizar a Nuget - v10.0.0 , comencé a recibir el siguiente error de compilación.

El tipo 'TRequest' no se puede utilizar como parámetro de tipo 'TRequest' en el tipo o método genérico 'IPipelineBehavior<TRequest, TResponse>'. No hay conversión de boxeo o conversión de parámetro de tipo de 'TRequest' a 'MediatR.IRequest'

Logré encontrar la guía de portabilidad del repositorio oficial de MediatR . Pero no pude encontrar ningún ejemplo.

¿Me estoy perdiendo algo más? Por favor, ¿alguien puede ayudarme con esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

También debe especificar el tipo de su parámetro TRequest en su clase abstracta. Tiene que ser al menos específico como parámetro en la interfaz que está intentando implementar.

 internal sealed class AppLoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : MediatR.IRequest<TResponse> // <- this is the part you're missing { // rest of your code... }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!