• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Sholtee / router / 332

21 Aug 2024 05:38AM UTC coverage: 93.448% (-0.3%) from 93.758%
332

push

appveyor

Sholtee
introduce ModuleRegistration class

1526 of 1633 relevant lines covered (93.45%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.0
/SRC/Public/Extensions/AsyncRouterBuilderAddRouteExtensions.cs
1
/********************************************************************************
2
* AsyncRouterBuilderAddRouteExtensions.cs                                       *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Reflection;
8

9
namespace Solti.Utils.Router.Extensions
10
{
11
    /// <summary>
12
    /// Defines some extension methods on <see cref="AsyncRouterBuilder"/>.
13
    /// </summary>
14
    public static class AsyncRouterBuilderAddRouteExtensions
15
    {
16
        /// <summary>
17
        /// The <see cref="Extensions.RequestHandlerBuilder"/> to be used. The default is <see cref="MsDiRequestHandlerBuilder"/>
18
        /// </summary>
19
        public static RequestHandlerBuilder RequestHandlerBuilder { get; set; } = new MsDiRequestHandlerBuilder();
1✔
20

21
        /// <summary>
22
        /// Begins a registration block where each route is bound to a specific module.
23
        /// </summary>
24
        public static ModuleRegistration<TModule> UseModule<TModule>(this AsyncRouterBuilder self) => new(self, RequestHandlerBuilder);
1✔
25

26
        /// <summary>
27
        /// Registers a new route.
28
        /// </summary>
29
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
30
        /// <param name="route">Route to be registered.</param>
31
        /// <param name="handler">Method accepting requests on the given route. You may pass async and sync callbacks as well.</param>
32
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
33
        /// <exception cref="ArgumentException">If the route already registered.</exception>
34
        public static void AddRoute(this AsyncRouterBuilder self, ParsedRoute route, MethodInfo handler, params string[] methods)
35
        {
1✔
36
            if (self is null)
1✔
37
                throw new ArgumentNullException(nameof(self));
×
38

39
            self.AddRoute
×
40
            (
×
41
                route,
×
42
                RequestHandlerBuilder.CreateFactory(route, handler, null),
×
43
                methods
×
44
            );
×
45
        }
×
46

47
        /// <summary>
48
        /// Registers a new route.
49
        /// </summary>
50
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
51
        /// <param name="route">Route to be registered.</param>
52
        /// <param name="handler">Method accepting requests on the given route. You may pass async and sync callbacks as well.</param>
53
        /// <param name="splitOptions">Specifies how to split the <paramref name="route"/>.</param>
54
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
55
        /// <exception cref="ArgumentException">If the route already registered.</exception>
56
        public static void AddRoute(this AsyncRouterBuilder self, string route, MethodInfo handler, SplitOptions splitOptions, params string[] methods) => self.AddRoute
×
57
        (
×
58
            RouteTemplate.Parse(route, self.Converters, splitOptions),
×
59
            handler,
×
60
            methods
×
61
        );
×
62

63
        /// <summary>
64
        /// Registers a new route.
65
        /// </summary>
66
        /// <param name="self"><see cref="AsyncRouterBuilder"/> instance.</param>
67
        /// <param name="route">Route to be registered.</param>
68
        /// <param name="handler">Method accepting requests on the given route. You may pass async and sync callbacks as well.</param>
69
        /// <param name="methods">Accepted HTTP methods for this route. If omitted "GET" will be used.</param>
70
        /// <exception cref="ArgumentException">If the route already registered.</exception>
71
        public static void AddRoute(this AsyncRouterBuilder self, string route, MethodInfo handler, params string[] methods) => self.AddRoute
×
72
        (
×
73
            route,
×
74
            handler,
×
75
            SplitOptions.Default,
×
76
            methods
×
77
        );
×
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc