Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've used <a href="http://structuremap.sourceforge.net/Default.htm" rel="noreferrer">structure map</a> quite a bit. The rest of your question is pretty loaded. I'll try to explain the concept in an example.</p> <p>Suppose you created a website that will accept payments through PayPal. PayPal is now a dependency. But you don't want to code against a specific PayPal provider.</p> <p>Instead You would create and code against an interface like this..</p> <pre><code>interface IPaymentProcessor { bool ProcessPayment(amount, ....); } </code></pre> <p>All your paypal code would reside in a class that implements the methods of your interface. <code>PayPalPaymentProcessor</code> for example</p> <p>Now you have an object that you will actually use to process the payments. This could be a Controller(asp.net-mvc, ViewModel-wpf) or just a class as shown here.</p> <pre><code>class PaymentProcessor { private IPaymentProcessor _processor = null; public PaymentProcessor(IPaymentProcessor processor) { _processor = processor; } public bool ProcessTransaction(Transaction trans) { _processor.ProcessPayment(trans.amount, ...); } } </code></pre> <p>This is where an IoC comes in. Instead of you calling the constructor manually, you would let an IoC <em>inject</em> the dependency. </p> <pre><code>PaymentProcessor processor = ObjectFactory.GetInstance&lt;PaymentProcessor&gt;(); </code></pre> <p>This piece of code tells structure map "Anytime you see a constructor that needs an IPaymentProcessor, return a new PayPalPaymentProcessor". </p> <pre><code>ObjectFactory.Initialize(x =&gt; { x.ForRequestedType&lt;IPaymentProcessor&gt;().TheDefaultIsConcreteType&lt;PayPalPaymentProcessor&gt;(); }); </code></pre> <p>All this mapping is separate from your implementation code and you could swap out these at a later point with little refactoring needed. There is a lot more to IoCs, but that is a basic concept. You can automate the injection of constructors to avoid the calls directly to ObjectFactory as well.</p> <p>Hope this helps!</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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