-
Notifications
You must be signed in to change notification settings - Fork 89
Add behaviors registration for certain request types #75
base: master
Are you sure you want to change the base?
Conversation
That's what I need as well. Looking forward to get this feature. |
Hrmmmm....I think the problem is that I'd still want to do a generic constraint instead of a partially closed type. |
The problem with generic constraint is that it is a constraint. Even in your example
if you send through MediatR any request that does not satisfy constraint it will throw exception. |
@xneg can't you just constrain the request?
|
@lilasquared then my request that does not implement |
@lilasquared so the problem with that is ASP.NET Core DI does not support constrained generics. The only way to solve it is to not register constrained open generics, but instead to register only the closed types. |
Which I'm open for btw - if the only way we can get around constrained generics is to try and close the types, that's what we'd have to do. One problem is that I don't scan for request types at the moment, only handler types. If you gave me handlers in assembly B that refers to request types in assembly A, right now I don't know about assembly A. |
I think the responsibility for checking and adding assemblies to scan lies with those who will use this method. But I admit it can be not 100% robust in some corner cases. |
We can make it work through handlers: find handlers in the given assembly and take requests from them. Will it suit you? |
That’s about as good as we can do, I guess. Handlers have to be closed
anyway.
…On Mon, Aug 19, 2019 at 5:40 PM Yury Pastushenko ***@***.***> wrote:
Which I'm open for btw - if the only way we can get around constrained
generics is to try and close the types, that's what we'd have to do.
One problem is that I don't scan for request types at the moment, only
handler types. If you gave me handlers in assembly B that refers to request
types in assembly A, right now I don't know about assembly A.
We can make it work through handlers: find handlers in the given assembly
and take requests from them. Will it suit you?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#75?email_source=notifications&email_token=AAAZQMRLZ25OGYRBH5PFJF3QFMOMRA5CNFSM4ILRUH3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4UQDVQ#issuecomment-522781142>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAZQMR7SAMFHI2I35F2MV3QFMOMRANCNFSM4ILRUH3A>
.
|
We rewrote registrar. @jbogard , please take a look. |
@jbogard so what do you think? |
@jbogard please give us some feedback. copying this thing from one project to another is pretty annoying. |
Looks good - I realized I don't have an |
Reformat code using .editorconfig
Hi! I added .editorconfig and refomated code according to it. |
I think this can be closed as the .NET Core DI supports constrained generics as of 5.0 |
Hi!
When I use MediatR I miss one important feature. I want to register Behaviors not only for certain Request and Response or for generic TRequest and TResponse. But I also want behaviors that triggers on some generic request. I think the best way to explain what I want is to show the code:
So I want to register some behavior that triggers only on requests that implement ICommon:
With standard Microsoft.DependecyInjection I could not do such a thing. So I wrote an extension method that sort through all request that implement ICommon and register behavior for them. It looks like:
services.AddBehaviorsForRequest<ICommon>(typeof(Startup));
Maybe my implementation is naive and does not take into account corner cases but I think it is better than nothing.
If you accept my idea I can add tests for this functional.