Skip to content

Provides a Fluent Routing syntax as well as Functional Routes for AspNetCore 2.0+

License

Notifications You must be signed in to change notification settings

dotJEM/aspnetcore-fluentrouting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fluent Routing syntax for AspNetCore 2.0+

WIP! - This is still in it's very early stages and far from done. - Ideas and Contributions are still more than wellcome though!...

The main features are:

  • Define Routes in a Fluent Syntax
  • Define Routes that point to Functions rather than Controllers.

Examples

Adding the services:

services.AddFluentRouting();

Controller Routes

Simple Routing to Controllers:

app.UseFluentRouter(router => {
    router.Route("api/stuff/{parameter?}").To<MyController>();
});

Functional Routes

Minimal Hello World Route:

app.UseFluentRouter(router => {
    router.Route("hello").To(() => "Hello World");
});

HttpContext Hello World Route:

app.UseFluentRouter(router => {
    router.Route("hello").To(context => context.Request.Method + ": Hello World");
});

Parameters:

app.UseFluentRouter(router => {
    router.Route("hello/{type}/{id}")
        .To((FromRoute<string> type, FromRoute<int> id) => $"Fetch: {type} with id: {id}");
});

Services:

// Inject Service into Service Container...
interface IMyService {
    MyStuff Fetch(string type, int id);
}

app.UseFluentRouter(router => {
    router.Route("hello/{type}/{id}")
        .To((FromRoute<string> type, FromRoute<int> id, FromService<IMyService> service) => {
            return ((TService)service).Fetch(type, id);
        });
});

About

Provides a Fluent Routing syntax as well as Functional Routes for AspNetCore 2.0+

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published