Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Service Locator is <a href="https://stackoverflow.com/questions/9409068/why-is-mvc4-using-the-service-locator-anti-pattern">generally an anti-pattern</a>, but the important thing is to understand <strong>why</strong> it's an anti-pattern. The reasons are usually related to refactoring and type safety. I think the best way to determine if you are doing something wrong is to reduce the problem to it's absolute simplest requirements, and then judge the simplest path to get there.</p> <p>As I understand, your requirements are: </p> <ol> <li>Receive xml form data in a webservice </li> <li>Based on the form type, call the appropriate logic</li> </ol> <p>My further questions to you would be: </p> <ol> <li>How do you identify the form type? Is it a field in the xml document? (if so, use that)</li> <li>Are the form types likely to change often?</li> </ol> <p>When it boils down to it, you have to use some sort of identifier. As @McGarnagle pointed out, magic strings can get out of sync with the code. You could use the Type name of the Strategy class, but it has the same 'might get out of sync' problem.</p> <p>If the form types aren't likely to change, just use a switch statement and instantiate the Strategy instances yourself. Simplicity is the best design pattern to follow for maintainability.</p> <p>If they are likely to change, Service Locator could work. If your Service Locator implementation is confined to just this code, it's not going to be that terrible to maintain.</p> <p>And on Ninject, I'm not sure if this <a href="http://www.servicestack.net/benchmarks/" rel="nofollow noreferrer">benchmark</a> is still valid, but <a href="http://funq.codeplex.com/" rel="nofollow noreferrer">Funq</a> is much faster, and I like the syntax better. (If you decide to use a DI container at all)</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