Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have come across an <a href="http://mikehadlow.blogspot.com/2010/01/10-advanced-windsor-tricks-1.html" rel="nofollow">article</a> on Mike Hadlow's blog that uses a delegate registered with Windsor to return one of a number of named type registrations...</p> <p>So basically the Windsor registration might look something like this...</p> <pre><code> container .Register( Component.For&lt;IReportFormatter&gt;().ImplementedBy&lt;ReportFormatterWord2003&gt;().Named("word2003"), Component.For&lt;IReportFormatter&gt;().ImplementedBy&lt;ReportFormatterWord2007&gt;().Named("word2007"), Component.For&lt;IReportFormatter&gt;().ImplementedBy&lt;ReportFormatterPdf&gt;().Named("pdf"), Component.For&lt;Func&lt;string, IReportFormatter&gt;&gt;().Instance(container.Resolve&lt;IReportFormatter&gt;), Component.For&lt;Foo&gt;()); </code></pre> <p>and the Foo constructor would take a parameter of the delegate type</p> <pre><code>Foo(Func&lt;string, IReportFormatter&gt; reportFormatterFactory) </code></pre> <p>now when Windsor resolves Foo, reportFormatterFactory is not resolved to an implementation of IReportFormatter instead it simply holds a reference to the container.Resolve method...</p> <pre><code>container.Resolve&lt;IReportFormatter&gt;(string) </code></pre> <p>that can later be used to get the correct IReportFormatter by calling...</p> <pre><code>reportFormatterFactory("word2007"); </code></pre> <p>Perhaps not as easy to understand as registering a factory but does away with the need for the factory class.</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