MVC and polymorphism

Jun 30, 2008 at 8:44 AM

I have just installed Web Service Factory which a great idea, thank you all for that.
At first glance I just wonder something:  why the attributes _presenter and _view are generated in each page and not a property of the parent class? The "correct" type (dynamic type) would be set when instanciating the presenter/view.

The generated code on the page, in the Page_Load, could also be encapsulated in a parent class in a virtual method which could be overriden. Because it is not, it seems to me OnViewLoaded and onViewInitialized could be not virtual at all:  what is the use to define OnViewLoaded and onViewInitialized on a common parent class if their invocations only refer to implementation in child classes?

My problem is the following:  I want all my pages to have a specific behavior when loaded.  I wanted to create an intermediate class of my own, child of Microsoft.Practices.CompositeWeb.Web.UI.Page, in order to code something here and make all my pages derive from this specific page.
But there is no virtual method to override in the pages, and no common attributes : _presenter is generated in each view.
It means I cannot share any common behavior and will have to copy/paste specific codes in views.

I was planning to move code in he parent class as I described (presenter attribute and Page_Load implementation), and only have the following code in the views:

protected void Page_Load(object sender, EventArgs e)
this.OnPageLoaded(sender, e);

where OnPageLoaded is a virtual method I can override in an intermediate class.

Is there a better way to deal with it? 

Joel Bloch