Hey all,
I have been very busy lately working on a new project that uses MVP. We are plugging along and everything was going very nicely until we got to our event viewer page in our admin menu. We are using a custom implementation of the standard .NET 2.0 web event schema that we built using the MVP pattern. I want to use a RadGrid for the main display because it is a nice package for our requirements (toggle, click to expand, etc). This brings me to the problem. With MVP, the user interface is extremely thin. We built the classes and code using TDD best practices, and unfortunately, we didn't do our homework on the RadGrid very well. We mistakenly counted the NeedDataSource event as a standard EventHandler (like most other event delegates that perform data binding). What could we do to resolve this problem? Keep in mind that the obvious solution (adding the Telerik.Web.UI reference to my presenter, and model projects) is absolutely out of the question.
View Interface
Presenter Class
Here is where things go sideways. I get the following error in the code below. Cannot implicitly convert type 'System.EventHandler' to 'Telerik.Web.UI.GridNeedDataSourceEventHandler'.
I am having trouble figuring out how to solve this without breaking the rules for MVP.
I love these engineering challenges, but this one has me pretty well stumped.
Any Thoughts?
Thanks,
John
I have been very busy lately working on a new project that uses MVP. We are plugging along and everything was going very nicely until we got to our event viewer page in our admin menu. We are using a custom implementation of the standard .NET 2.0 web event schema that we built using the MVP pattern. I want to use a RadGrid for the main display because it is a nice package for our requirements (toggle, click to expand, etc). This brings me to the problem. With MVP, the user interface is extremely thin. We built the classes and code using TDD best practices, and unfortunately, we didn't do our homework on the RadGrid very well. We mistakenly counted the NeedDataSource event as a standard EventHandler (like most other event delegates that perform data binding). What could we do to resolve this problem? Keep in mind that the obvious solution (adding the Telerik.Web.UI reference to my presenter, and model projects) is absolutely out of the question.
View Interface
public interface IEventViewerView |
{ |
event EventHandler StartUp; |
event EventHandler NeedDataSource; |
object DataSource { set; } |
object OnNeedDataSource { set; } |
} |
Presenter Class
public class EventViewerPresenter |
{ |
private readonly IEventViewerView _view; |
private readonly IEventViewerRepository _repo; |
public EventViewerPresenter(IEventViewerView view) : this(view, new EventViewerRepository()) |
{ |
} |
public EventViewerPresenter(IEventViewerView view, IEventViewerRepository repo) |
{ |
if (view == null) |
throw new ArgumentNullException("view may not be null"); |
if (repo == null) |
throw new ArgumentNullException("repo may not be null"); |
_view = view; |
_repo = repo; |
_view.NeedDataSource += new EventHandler(_view_NeedDataSource); |
_view.StartUp += new EventHandler(_view_StartUp); |
} |
void _view_NeedDataSource(object sender, EventArgs e) |
{ |
_view.OnNeedDataSource = _repo.List(); |
} |
void _view_StartUp(object sender, EventArgs e) |
{ |
_view.DataSource = _repo.List(); |
} |
} |
Here is where things go sideways. I get the following error in the code below. Cannot implicitly convert type 'System.EventHandler' to 'Telerik.Web.UI.GridNeedDataSourceEventHandler'.
protected void Page_Load(object sender, EventArgs e) |
{ |
_presenter = new EventViewerPresenter(this); |
grdEvents.NeedDataSource += NeedDataSource; // Errors here... |
if (StartUp != null) StartUp(this, EventArgs.Empty); |
} |
public event EventHandler StartUp; |
public event EventHandler NeedDataSource; |
public object DataSource |
{ |
set |
{ |
if (!IsPostBack) |
{ |
grdEvents.DataSource = value; |
grdEvents.DataBind(); |
} |
} |
} |
public object OnNeedDataSource |
{ |
set { grdEvents.DataSource = value; } |
} |
I am having trouble figuring out how to solve this without breaking the rules for MVP.
I love these engineering challenges, but this one has me pretty well stumped.
Any Thoughts?
Thanks,
John