ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

WithCtorParam in InterceptExtensions #66

Closed HamedMousavi closed 7 years ago

HamedMousavi commented 7 years ago

Trying interceptor I looked at your test code to figure how it works. Apparently we need to create an extension method called Intercept which is used in this test: https://github.com/ipjohnson/Grace/blob/b7869f21b8a4faaac2ca3c731bc0e5dcce5882f4/tests/Grace.Tests/DependencyInjection/Intercept/InterceptionExtensions.cs#L11

After copying this class to the solution I encountered this error: 'IFluentDecoratorStrategyConfiguration' does not contain a definition for 'WithCtorParam'...

ipjohnson commented 7 years ago

Hi Hamed,

Sorry about that decorators were a new feature for 5.0 and didn't support WithCtorParam at initial release. For 5.1.0 I'm adding WithCtorParam support for decorators and that test is new.

As luck would have it I'm releasing 5.1.0 today. I'll leave a comment once I've done the release and you can tell me how it works for you.

ipjohnson commented 7 years ago

Just to give you a little more background. Support for interceptors in 4.0 & 5.0 weren't fully supported and required a function to be provided at registration time to create the proxy. This was really slow so I created issue #65 to add WithCtorParam support allowing greater control over decorator construction making interception easier and more performant (~8x).

ipjohnson commented 7 years ago

I just released 5.1.0, try it now.

HamedMousavi commented 7 years ago

THANK YOU SO MUCH!

This now works perfectly fine, thank you.

Just a minor problem, I guess. If I create the wrapping class (in the test example: Calculator) as Singleton and then create an interceptor (also as singleton) I run into this runtime error: "Grace.DependencyInjection.Exceptions.RecursiveLocateException: 'Recursive object graph detected" I don't need the wrapped class to be Singleton so no problem for me but it's probably a bug. I included the stack trace of the exception.

BTW, Grace is an awesome container, thank you very much for all the efforts. :-)

StackTrace.txt

ipjohnson commented 7 years ago

Interesting I hadn't tried that but does sound like a problem as you should be able to decorate a singleton like that. I'll open a new defect and track that.

Thanks for the compliment.