Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>thanx to Marijin's insight this has been nailed!</p> <p>Firstly consider this all-purpose utility class</p> <pre><code>public class ServiceLocatorImplementer : IMethodReplacer { private readonly Type _forType; public ServiceLocatorImplementer(Type forType) { this._forType = forType; } protected IEnumerable GetAllImplementers() { var idObjects = Spring.Context.Support.ContextRegistry.GetContext() .GetObjectsOfType(_forType); return idObjects.Values; } public object Implement(object target, MethodInfo method, object[] arguments) { return GetAllImplementers(); } } </code></pre> <p>declare it with this configuration sample</p> <pre><code>&lt;object id="FindInterfaceUsages" type="ServiceLocatorImplementer, SpringDependendAssembly"&gt; &lt;constructor-arg name="forType"&gt; &lt;object type="System.Type" factory-method="GetType"&gt; &lt;constructor-arg type="string" name="typeName" value="Foo.Bar.IChe, NONSpringDependendAssembly" /&gt; &lt;!-- i use the strict overload --&gt; &lt;constructor-arg type="bool" name="throwOnError" value="true" /&gt; &lt;constructor-arg type="bool" name="ignoreCase" value="false" /&gt; &lt;/object&gt; &lt;/constructor-arg&gt; &lt;/object&gt; &lt;object id="MightyPirate" type="Foo.Pirates, NONSpringDependendAssembly"&gt; &lt;replaced-method name="GetAllICheImplentations" replacer="FindInterfaceUsages" /&gt; &lt;/object&gt; </code></pre> <p>and finally inject to the required target</p> <p>What is trully great with this methodology is that the underlying GetObjectsOfType is <strong>not</strong> going to be called until you actually execute <code>GetAllICheImplentations()</code> (unless you try to execute it during spring init which is not going to bode well)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload