Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The interesting part of your question to me is: how to use service locator functions (such as spring.net's <code>IApplicationContext.GetObjectsOfType(...)</code>) from within your library, without introducing a dependency on a specific IoC container.</p> <p>As stated in the question, this is useful, because we want to build libraries that do not force the consumer to use a specific IoC container. However, we still want to use <em>an</em> IoC container, because it eases the development of our library. This dilemma is nicely described by Jeremy Miller in the post <a href="http://codebetter.com/jeremymiller/2008/08/16/it-s-time-for-ioc-container-detente/" rel="nofollow">"It’s time for IoC Container Detente"</a>.</p> <p>His blog post has led to a <a href="http://commonservicelocator.codeplex.com/" rel="nofollow">small project on codeplex called CommonServiceLocator</a>. This project specifies an <a href="http://commonservicelocator.codeplex.com/SourceControl/changeset/view/27688#332676" rel="nofollow">IServiceLocator interface</a> for service location, that is implemented by many popular IoC containers, including Spring.NET.</p> <p>The <code>IServiceLocator</code> defines a <code>IEnumerable&lt;TService&gt; GetAllInstances&lt;TService&gt;();</code> method, which basically is what is asked for in your question.</p> <p>When your library needs service locator functionality, you can take a dependency on the CommonServiceLocator library and you and other consumers can wire it up using your IoC container of choice.</p> <p>And guess what: Spring.NET adapter implements <code>IEnumerable&lt;TService&gt; GetAllInstances&lt;TService&gt;();</code> using <code>GetObjectsOfType(serviceType);</code>.</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