Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>I'll leave this answer here for future reference, but I like my <a href="https://stackoverflow.com/questions/5026711/possible-getobjectsoftype-replacement/5156853#5156853">other answer</a> better.</em> </p> <p>The original answer is rather lenghty and very specific to the example in the question. </p> <p>I don't think there is a configuration equivalent to <code>GetObjectsOfType(...)</code>.</p> <p>However, isn't it very easy to get rid of the Spring.net dependency?</p> <p>Let me see if I understand correctly:</p> <pre><code>// sharedLib contains ICustomInterfaceThatDoesSomething // by "--&gt;" I mean "depends on" webApp --&gt; Spring.Core, Spring.Web webApp --&gt; sharedLib sharedLib --&gt; Spring.Core // only to call GetObjectsOfType(...) on Spring container </code></pre> <p>We want to get rid of the last dependency, because we want to be able to use <code>sharedLib</code> in combination with another DI container. In <code>sharedLib</code> we have a class that needs to signal all <code>ICustomInterfaceThatDoesSomething</code> implementations to do something. For this purpose I'd create:</p> <pre><code>MySomethingManager { public MySomethingManager() {} public MySomethingManager(IMySomethingDoerProvider prov) { // init SomethingDoers } IList&lt;ICustomInterfaceThatDoesSomething&gt; SomethingDoers { get; set; } void SignalAllToDoSomething() { foreach (var doer in Provider.SomethingDoers ) doer.DoSomething(); } } IMySomethingDoerProvider { IList&lt;ICustomInterfaceThatDoesSomething&gt; GetAll(); } </code></pre> <p><code>MySomethingManager</code> used to contain the Spring dependency, but now it's Spring Free. Now I have two options when wiring up <code>sharedLib</code> with regard to <code>MySomethingManager</code>:</p> <ol> <li>using property injection on <code>MySomethingManager.SomethingDoers</code> with a <code>List&lt;ICustomInterfaceThatDoesSomething&gt;</code></li> <li>using constructor injection with an <code>IMySomethingDoerProvider</code> implementation</li> </ol> <p>Both can be done using Spring and many other DI containers. You can use the first approach if you don't mind listing all <code>ICustomInterfaceThatDoesSomething</code> in the configuration.</p> <p>If you want magical <code>GetObjectsOfType(...)</code> code, you can use the features of your DI container to create a <code>IMySomethingDoerProvider</code>.</p> <p>When using Spring, the second approach would require to create:</p> <pre><code>MySomethingDoerSpringProvider: IMySomethingDoerProvider { IList&lt;ICustomInterfaceThatDoesSomething&gt; GetAll() { // use Spring.Context.Support.ContextRegistry.GetContext() // .GetObjectsOfType(typeof (ICustomInterfaceThatDoesSomething)); } } </code></pre> <p>Which you can place in a project that depends on <code>sharedLib</code>. Since your <code>webApp</code> already depends on Spring.Core, you could place <code>MyProvider</code> there to get you started quickly.</p> <p><em>Notes</em></p> <p>If <code>DoSomething</code> is called once per instance, you might consider specifying an initialization method instead.</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.
 

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