I want to create an object with a constructor containing predicate and func objects in the xml config using spring. The Predicate and the Func arguments should point to a method of another configured object. How is this possible using Spring.net? I was not able to find a solution or hint in the documentation…
A sample constructor would be:
MyClass(Predicate<TInput> condition, Func<TInput, TOutput> result)
I solved the problem using an intermediate “factory” inspired by the suggestion of thekip but leaving the object requiring the predicate and func in the constructor (MyClass in the example above) untouched. This solution keeps the “problem” of handling delegates in spring outside of the implementation of MyClass (in opposite of the suggestion of thekip, but thanks for your answer).
Here is my way to configure such a situation (setting delegates in Spring.Net, using object based factory pattern).
The MyDelegator class a sample implementation for predicate/func to use
(object here, but could be anything else fitting to the predicate/func params):
… then you need a container for the object with the predicate and or func (could
be in seperate classes, too) …
… and this can be configured in Spring.Net xml this way
And now you can use this anywhere in your config for objects with predicate/func
(no need to change the class requiring the predicate/func)
That’s it. Any suggestions to improve this solution? Maybe, Spring.net already has a generic solution for this…