Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you're looking for the <a href="http://www.springframework.net/doc-latest/reference/html/objects.html#objects-method-injection-lookup" rel="nofollow">lookup-method injection</a> feature.</p> <p>You have loaded the Spring.NET application context somewhere at the start. The code-based dependency on Spring.NET there is minimal. The problem is that everywhere you need an (adviced) service, you explicitly depend on Spring.NET with <em>ContextRegistry.GetContext()..</em></p> <p>You can work around that with method replacement using <em>lookup-method</em>, example:</p> <p>Create an AbstractCommandFactory:</p> <pre><code>namespace MyNamespace { public abstract class AbstractCommandFactory : ICommandFactory { public abstract ICommand getMyCommand(); } } </code></pre> <p>Using Spring.NET you can <em>getMyCommand</em> return a Spring.NET object:</p> <pre><code>&lt;objects&gt; &lt;object id="commandfactory" type="MyNamespace.AbstractCommandFactory, MyAssembly"&gt; &lt;lookup-method name="getMyCommand" object="commands.mycommand" /&gt; &lt;/object&gt; &lt;object id="commands.mycommand" type=MyNamespace.MyCommandImplementation, MyAssembly" /&gt; &lt;/objects&gt; </code></pre> <p>Now when you initialize the Spring.NET Application Context, load this command factory and pass the reference along. When you need an instance of MyCommandImplementation, you just request one from the factory instance:</p> <pre><code>public void doSomeWork() { // factory is an ICommandFactory // instantiated earlier using the explicit context.getObject("commandfactory") ICommand myCommand = this.factory.getMyCommand(); myCommand.Execute(); } </code></pre> <p>Now your explicit dependency on Spring.NET is very minimal: only at the initial load + instantiation of your factories. The rest of your code stays clean.</p> <p>Bonus points: you can more easily create ICommandFactory/ICommand mocks to unit-test your code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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