Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To solve this problem you could use property injection.</p> <p>First, register <strong>ShipperOperations</strong>, <strong>Navigator</strong> and <strong>ShipperPresenter</strong> in the DI container.</p> <p>Then, in the Page_Load method of your view, invoke the resolve method of the DI container of your choice.</p> <pre><code>public class ShipperPresenter { IShipper shipperView; IShipperOperations operations; INavigator navigator; public ShipperPresenter(IShipperOperations operations,INavigator navigator) { this.operations = operations; this.navigator = navigator; } public IShipper ShipperView { get { return shipperView; } set { shipperView = value; } } ... } </code></pre> <p>And the view would look like this:</p> <pre><code>public partial class ShipperView : System.Web.UI.Page, IShipperView { ShipperPresenter presenter; protected void Page_Load(object sender, EventArgs e) { presenter = YourIOC.Resolve&lt;ShipperPresenter&gt;(); presenter.ShipperView = this; } ... } </code></pre> <p>You could also use a factory to create the presenter at runtime, while passing it the parameters of your choice. In fact, in a DI world, this is THE way to proceed when you want to instantiate objects with dependencies that are only known at runtime. There is a nice mechanism for this in Castle Windsor, it's called <a href="http://stw.castleproject.org/Default.aspx?Page=Typed-Factory-Facility-interface-based-factories&amp;NS=Windsor&amp;AspxAutoDetectCookieSupport=1" rel="nofollow">typed factories</a>.</p> <p>Using a factory, no need to modify the presenter class. Instead, create an interface for the factory:</p> <pre><code>public interface IShipperPresenterFactory { ShipperPresenter Create(IShipper shipperView); } </code></pre> <p>If using Windsor, the only thing that you have to do is to register this interface as a typed factory. With other DI containers, you will have to implement a class that uses the DI container internally to resolve the presenter.</p> <p>The Page_Load method of the view would then use the factory like this:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { var factory = YourIOC.Resolve&lt;IShipperPresenterFactory&gt;(); presenter = factory.Create(this); } </code></pre>
    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