jbogard / MediatR

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

Registering generic handlers #905

Closed sjd2021 closed 1 year ago

sjd2021 commented 1 year ago

This PR to register generic request handlers (RegisterGenericMediatRHandlers) was opened in the old MediatR repository and closed. Is there an issue with it being ported over, as-is, or as close to that as possible since registration has somewhat changed?

https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/pull/115

jbogard commented 1 year ago

No there's no issue with someone doing that.

sjd2021 commented 1 year ago

@amunim I've set this up locally, and it doesn't actually seem to work for this handler:

  public MyMediatrRequest<T> : IRequest<Paged<T>>, IBaseRequest
  {

      public MyMediatrHandler : IRequestHandler<MyMediatrRequest<T>, Paged<T>>
      {
      }
  }

No service for type 'MediatR.IRequestHandler2...`

This isn't working. Any idea why?

amunim commented 1 year ago

I have exams... will look into it by the end of the month

jbogard commented 1 year ago

I don't think the stock container can handle this anyway, you might need AutoFac or something else.

sjd2021 commented 1 year ago

I have exams... will look into it by the end of the month

ok please let me know what you find. I'm willing to take up anything if you can provide insight on what is missing between now and when this was working for you (aside from namespaces/nuget packages being moved around).

advdotnet commented 6 months ago

@sjd2021 or anyone stumbling upon this issue: