Question

I'm implementing a Cart functionality in a ASP project using the WebformsMVP Framework to ease the testability with webforms. My presenter does several operations, and then asks the view to redirect to specific pages depending on the situation. Here is the interface between the presenter and the view implementation:

    public interface IAddToCartView : IView
    {
        event Action DoPurchase;
        event Action DoAddToWishList;

        MarketId MarketId { get; }

        VariationContent VariationContent { get; }

        string ErrorMsg { get; set; }

        string WarehouseCode { get; set; }

        decimal Quantity { get; set; }

        void GoToCartPage();

        void GoToWishListPage();
    }

In the presenter, when the adding to cart functionality is done, the presenter executes View.GoToCartPage() or View.GoToWishListPage(). I think that filling the view interface with "redirect" details somewhat reveals to the presenter what is the background implementation of the view (meaning that the presenter knows that the implementation behind the interface can perform redirects).

Is there any other more elegant way to do what I'm saying?

Thank you very much and kind regards.

Was it helpful?

Solution

Ok, I solved it. I implemented an EventArgs action in the interface and delegated the responsibility of doing redirections to the presenter in the following way:

public interface IAddToCartView : IView
{
    event Action DoPurchase;
    event Action DoAddToWishList;
    event Action RedirectToWishListPage; 
    ...
}

Then, I created an INavigator interface which exposes a method "Redirect", and implemented by a Navigator class through Inversion of Control with Ninject. This way I could also abstract the details of HTTPContext from the presenter class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top