ActionResult navigation

Topics: Feature Requests
Oct 6, 2013 at 3:36 PM
Edited Oct 9, 2013 at 5:09 PM
I partially implemented ASP.NET MVC navigation for Caliburn actions, but its not mature enough and not integrated with other features.. It would be great if whole window/view/composition management logic be unified in this way.. I couldn't say how much it can simplifies the navigation system! Other ASP.NET MVC features like action filters and model binders can be suggested here..
    public class Bootstrapper : Caliburn.Micro.Bootstrapper<LoginViewModel> {
        protected override void Configure() {
            ActionMessage.InvokeAction = (ActionExecutionContext context) => {
                var values = Caliburn.Micro.MessageBinder.DetermineParameters(context, context.Method.GetParameters());
                var returnValue = context.Method.Invoke(context.Target, values);
                var result = returnValue as ActionResult;
                if (result != null) {
                    result.Execute(context);
                }
            };
        }
    }

    public abstract class ActionResult {
        public abstract void Execute(ActionExecutionContext context);
    }
    public class WindowResult : ActionResult {
        private object model;
        public WindowResult(object model) {
            this.model = model;
        }
        public override void Execute(ActionExecutionContext context) {
            new WindowManager().ShowWindow(model);
        }
    }

    public class MessageBoxResult : ActionResult {
        private string message;
        public MessageBoxResult(string message) {
            this.message = message;
        }
        public override void Execute(ActionExecutionContext context) {
            MessageBox.Show(message);
        }
    }

    public abstract class Controller : Conductor<object> {
        public WindowResult Window(object model) {
            return new WindowResult(model);
        }

        public MessageBoxResult MessageBox(string message) {
            return new MessageBoxResult(message);
        }
    }

    public class LoginViewModel : Controller {
        public ActionResult Login(string username, string password) {
            if (/* validation logic */) return Window(new ShellViewModel());
            return MessageBox("Incorrect user name or password");
        }
    }

    public class ShellViewModel : Controller { }