Say I have the controller as follows:
public class Controller
{
ISomeService _service;
public Controller(ISomeService service)
{
_service = service;
_service.EventFired += EventFired;
_service.SomeEventFired += SomeOtherEventFired;
}
private void EventFire(object sender, EventArgs e)
{
// Might occur on FireSomeEvents();
// Go to another controller
}
private void SomeOtherEventFired(object sender, EventArgs e)
{
// Might occur on FireSomeEvents();
// Go to another view on this page
}
public void Create()
{
_service.FireSomeEvents();
if(EventFired == true)
{
return View("EventFired");
}
else
{
return RedirectToAction("SomeOtherEventFired");
}
}
}
I want to be able to handle the Redirect and View in a better way, because in the end I will end up with 3 potential events on my service.
I’m just wondering whether this is a design smell, or whether there is a better way to implement the redirect to pages…
Events don’t play nicely with ASP.NET MVC. Their model is not adapted to the MVC pattern. If you want to use them you may take a look at asynchronous controllers.