-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to register decorator classes? #149
Comments
I took a quick look and out of the box you can't do what you want to do but I think it's possible to do it with a C# extension. I'll write up an example of how to do it and post a gist of it. I also think this is a worth feature request so I'll see about making it part of Grace officially so you don't have to do an extension. |
@davidkeaveny did the unit test for dectorators work for you? Also what are your thoughts on C# extension vs a member on the interface? |
It works flawlessly 👍 Would the extension method basically replace the |
Hmm, maybe I jumped the gun a little bit - the first decorator that I register works flawlessly (the I've tried switching it round, and get the same result - register one decorator, all is good; register two decorators, all is bad. The error that Grace throws is:
|
Hmm, I can see the piece of code that must have failed to end up in that situation (it's having an issue building the closed generic type for activation). Would it be possible for you to create a small sample using your types that you want to decorate and the decorators that are failing? You can remove the logic from the classes as I think it's probably some corner case of generics that I'm missing but I'm not able to create it using my simple test cases. |
I've prepared a repro - the bug appears if there are multiple decorators registered, so if you comment out one or other of the decorator registrations the test passes. I also modified the decorators so that they had no other dependencies (apart from the |
Thanks @davidkeaveny that was very helpful. I was able to replicate the problem and fix it. I should be able to find some time this weekend to look at the other generic issue you raised but I'm not sure what/if there is a fix for it. Either way I should be able to get a new version out for you this weekend. In the mean time if you want you can try the nightly build at https://ci.appveyor.com/nuget/grace-master |
I've released version 6.3.3 to address this issue and I'm marking it closed |
Looks great, @ipjohnson , thanks! |
If I have an abstract base class
CommandHandler<T>
, and I want to register a decorator classLoggingCommandHandler<T>
such that every class that implements the base class is resolved with the decorator class, how do I tell Grace to achieve such a thing?How about if I want to add another decorator class
ValidatingCommandHandler<T>
and I want the order of the decorator classes to be preserved? i.e. always resolve as:The text was updated successfully, but these errors were encountered: