Git Product home page Git Product logo

navigation's Introduction

Current status (10/2018):

This is repository is going be rewritten to general navigation framework with WPF and ASP.NET implementations - blueprint.

Build status


AspNet.Navigation

Model (class) base navigation and routing for ASP.NET (Core) MVC

NuGet

This library is distributed on NuGet under APACHE 2.0 license.

Introduction

The ASP.NET routing and link creation is missing type safety. In this library the routing is based on models, a C# define classes for each route. We can quite simply satify default route from MVC with model:

[Route("{Controller}/{Action}/{Id?}")
public class MvcRoute : RouteModel
{
    public string Controller { get; private set; }
    public string Action { get; private set; }
    public int? Id { get; private set; }
    
    public MvcRoute(string controller, string action, int? id = null)
        : base(null)
    {
        Controller = controller;
        Action = action;
        Id = id;
    }
}

And then, when creating link in Razor's .cshtml, we can use:

@Html.ModelLink("Go Home!", new MvcRoute("Home", "Index"))

This is a bit better, but not that much. Let's see how we can declare route from blog post. We want url in form like blog/{Year}/{Month}/{Day}/{Slug}. In the standart MVC, we need to create route link like this:

@Html.RouteLink("View post", new { 
    Year = post.PublishedAt.Year, 
    Month = post.PublishedAt.Month, 
    Day = post.PublishedAt.Day, 
    Slug = post.Slug 
})

But when using Neptuo.AspNet.Navigation, we can do the same with this code:

@Html.ModelLink("View post", new BlogPostRoute(post.PublishedAt, post.Slug))

We also benefit from the fact, then the model can deconstruct the date itself. So route model is defined like:

[Route("blog/{Year}/{Month}/{Day}/{Slug}")]
public class BlogPostRoute : RouteModel
{
    public int Year { get; private set; }
    public int Month { get; private set; }
    public int Day { get; private set; }
    public string Slug { get; private set; }
    
    public BlogPostRoute(DateTime publishedAt, string slug)
    {
        Year = publishedAt.Year;
        Month = publishedAt.Month;
        Day = publishedAt.Day;
        Slug = slug;
    }
}

Sample web application (in the src/sample) contains usage of all features, including route constraints.

Route registration

The registration process is pretty straightforward, just add the model to the route collection using extension method:

routes.MapModel<BlogPostRoute>();

Reading the parameters in the controller action method

We can easily use the route class in the parameter of action method to bind-in parameters. Note that for this use the property setters must be public.

public class BlogController
{
    public ActionResult Post(BlogPostRoute parameters)
    {
        // TODO: Find blog post by Year, Month, Day and Slug...
    }
}

License

Apache 2.0

navigation's People

Contributors

maraf avatar

Watchers

James Cloos avatar  avatar

navigation's Issues

A generic message box

Navigation rules:

  • Message box.
  • Ask/Confirm with standard buttons.

WPF implementation:

  • Mapping to MessageBox Moved to #12.

Should INavigator be an interface?

Not sure if there could ever be any other implementation, as INavigator is only query interface (using feature model) for other services.

Solution structure

Organize project into these solution folders:

  • Contracts
  • Implementations
  • Tests
  • TestApps

WPF implementation

The goal for WPF is to completely manage windows in navigation framework. It is responsible for window modality, resolving continuation tasks, reactivating current window if this is registered as singleton, closing other windows not compatible/excluding with the one to open.

All these rules seems quite hard to declaratively define.

  • Associating navigation rule with view by registering a IFactory.
  • Use RuleAttribute to make discover rules (use Neptuo.Reflection.ReflectionService?).
  • NavigateCommand (WPF impl. or Observables.Something assembly?).
  • Pass in a view manager to support some master-detail scenarios inside a single window.

WPF: Auto Window creation

Do not inherit from Window, instead create view based from Control (etc) and let navigation framework handle window instances.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.