Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:57:49+00:00 2026-06-04T21:57:49+00:00

I am creating an ASP.NET Web forms application with MVP pattern. The structure of

  • 0

I am creating an ASP.NET Web forms application with MVP pattern. The structure of my view is something like this:

public partial class ShipperView : System.Web.UI.Page, IShipperView
{
       ShipperPresenter presenter;
       public ShipperOperationsView()
        {
            IShipperOperations operations = new ShipperOperations();
            INavigator navigator = new Navigator();
            presenter = new ShipperPresenter(this,operations,navigator);  //Instantiating presenter
        }
        ...
}

The basic structure of my presenter is something like this:

public class ShipperPresenter
{
        IShipper shipperView;
        IShipperOperations operations;
        INavigator navigator;
        public ShipperPresenter(IShipperView view,IShipperOperations operations,INavigator navigator)
        {
            shipperView = view;
            this.operations = operations;
            this.navigator = navigator;
        }
        ...
}

I don’t want to instantiate my presenter using the new keyword, I would like to replace it with resolving dependency. During the dependency resolution, I want to pass the instance of the present view to the dependency resolver. I tried searching a lot on this but did not get any satisfactory answer.

Can this issue be resolved using any of the IoC containers like StructureMap, Ninject, Unity or MEF? Any pointer would be of great help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:57:52+00:00Added an answer on June 4, 2026 at 9:57 pm

    To solve this problem you could use property injection.

    First, register ShipperOperations, Navigator and ShipperPresenter in the DI container.

    Then, in the Page_Load method of your view, invoke the resolve method of the DI container of your choice.

    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; }
            }
            ...
    }
    

    And the view would look like this:

    public partial class ShipperView : System.Web.UI.Page, IShipperView
    {
           ShipperPresenter presenter;
    
           protected void Page_Load(object sender, EventArgs e)
           {
               presenter = YourIOC.Resolve<ShipperPresenter>();
               presenter.ShipperView = this;
           }
           ...
    }
    

    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 typed factories.

    Using a factory, no need to modify the presenter class. Instead, create an interface for the factory:

    public interface IShipperPresenterFactory
    {
        ShipperPresenter Create(IShipper shipperView);
    }
    

    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.

    The Page_Load method of the view would then use the factory like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        var factory = YourIOC.Resolve<IShipperPresenterFactory>();
        presenter = factory.Create(this);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am intending in creating this tutorial in ASp.NET web forms. Is this possible?
I have an ASP .NET web application which uses Forms Authentication. Let's call this
I am working on creating a Web site like www.hipmunk.com in ASP.NET web forms.
I am thinking about creating my new asp.net mvc web application compatible with native
We're creating a new consumer/public-facing ASP.Net web app. There are two concerns: --Use cookie
I'm using the Entity Framework for an ASP.NET Web Forms application and I'm wondering
I am creating a web application using Form Authentication of Asp.Net with C# and
I am creating a solution from scratch, using ASP.NET Web forms C#. I am
I've developed a Web application in ASP.net web Forms (.net v4.0) which uses the
I am trying to set up my ASP.NET Web Forms (Framework 4.0) application to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.