jeudi 9 novembre 2017

Winforms to ASP.net migration with MVC pattern : how to manage events?

I'm creating an application in C#/Winforms which could be migrate on a Webserver in a few time, so I'm trying to perform the best pattern. My question is about the best way to manage events. In my point of view, I have 2 solutions.

First one:

Interface

public interface IAttributionView
{
    event ButtonClicked ControllerTestEvent;
}

Form

public delegate void ButtonClicked();    
public partial class AttributionFrm : Form,IAttributionView
{
    public event ButtonClicked ControllerTestEvent;

    public AttributionFrm()
    {
        InitializeComponent();
    }

    private void butTest_Click(object sender, EventArgs e)
    {
        ControllerTestEvent();
    }
}

Controller

public class AttributionController
{
    private IAttributionView _view;

    public AttributionController(IAttributionView view)
    {
        _view = view;
        view.ButtonClicked += new ButtonClicked(Test);
    }

    private void Test()
    {
        //Do Something
    }
}

Second one:

Form

public partial class AttributionFrm : Form,IAttributionView
{
    private AttributionController _controller;

    public AttributionFrm(AttributionController controller)
    {
        _controller=controller;
        InitializeComponent();
    }

    private void butTest_Click(object sender, EventArgs e)
    {
        _controller.Test();
    }
}

Controller

public class AttributionController
{
    private IAttributionView _view;

    public AttributionController(IAttributionView view)
    {
        _view = view;
    }

    private void Test()
    {
        //Do Something
    }
}

I don't know ASP.net at all, that's the reason why I would like to know from your opinion and experience what is the best approach to achieve that (simplicity of adaptation, complexity of code, or whatever)?

Many thanks.

Aucun commentaire:

Enregistrer un commentaire