コード例 #1
0
        public IConfigureRoutingConventions Build(Func <RouteBuilderInfo, IEnumerable <Route> > builder)
#endif
        {
            builder.MustNotBeNull();
            _lambda.Builder = builder;
            _parent.Add((IBuildRoutes)_lambda);
            return(_parent);
        }
コード例 #2
0
        /// <summary>
        /// This conventions applies only for GET requests
        /// </summary>
        /// <param name="policy"></param>
        /// <returns></returns>
        public static RoutingConventions UseOneModelInHandlerConvention(this RoutingConventions policy, Predicate <ActionCall> applyTo = null)
        {
            var convention = new OneModelInHandlerConvention(applyTo);

            policy.Add(convention);

            return(policy);
        }
コード例 #3
0
        /// <summary>
        /// Scans assembly and registers routing convetions but not configuration modules. Uses dependency resolver
        /// </summary>
        /// <param name="policy"></param>
        /// <param name="asm"></param>
        /// <param name="res">Null means it uses the current dependecy resolver</param>
        public static RoutingConventions RegisterConventions(this RoutingConventions policy, Assembly asm, IDependencyResolver res = null)
        {
            if (res == null)
            {
#if WEBAPI
                throw  new ArgumentNullException("res", "A dependency resolver instance is required for WebApi");
#else
                res = DependencyResolver.Current;
#endif
            }

            foreach (var builder in asm.GetTypesDerivedFrom <IBuildRoutes>())
            {
                policy.Add(res.GetInstance <IBuildRoutes>(builder));
            }

            foreach (var modifier in asm.GetTypesDerivedFrom <IModifyRoute>())
            {
                policy.Add(res.GetInstance <IModifyRoute>(modifier));
            }

            return(policy);
        }
コード例 #4
0
        public void route_is_generated_from_input_model()
        {
            var sut = new RoutingConventions();
            sut.Add((IBuildRoutes) new OneModelInHandlerConvention());
            sut.RegisterController<ModelFixtureController>();

            var routes = sut.BuildRoutes();
            routes.Count().Should().Be(1);
            var def = routes.Last();
            def.RouteTemplate.Should().Be("ModelFixture/{page}/{text}/{optional}");
            def.Defaults["controller"].Should().Be("ModelFixture");
            def.Defaults["action"].Should().Be("Get");
            def.Defaults.ContainsKey("page").Should().BeFalse();
            def.Defaults["text"].Should().Be(RouteParameter.Optional);
            def.Defaults["optional"].Should().Be(RouteParameter.Optional);
        }
コード例 #5
0
        public void route_is_generated_from_input_model()
        {
            var sut = new RoutingConventions();

            sut.Add((IBuildRoutes) new OneModelInHandlerConvention());
            sut.RegisterController <ModelFixtureController>();

            var routes = sut.BuildRoutes();

            routes.Count().Should().Be(1);
            var def = routes.Last();

            def.RouteTemplate.Should().Be("ModelFixture/{page}/{text}/{optional}");
            def.Defaults["controller"].Should().Be("ModelFixture");
            def.Defaults["action"].Should().Be("Get");
            def.Defaults.ContainsKey("page").Should().BeFalse();
            def.Defaults["text"].Should().Be(RouteParameter.Optional);
            def.Defaults["optional"].Should().Be(RouteParameter.Optional);
        }
コード例 #6
0
 public static RoutingConventions UseHandlerConvention(this RoutingConventions policy)
 {
     policy.Add(new HandlerRouteConvention());
     return(policy);
 }