/// <summary>
        /// Scans the calling assembly for all routes defined with AttributeRouting attributes,
        /// using the default conventions.
        /// </summary>
        public static void MapHttpAttributeRoutes(this HttpRouteCollection routes)
        {
            var configuration = new HttpWebConfiguration();
            configuration.AddRoutesFromAssembly(Assembly.GetCallingAssembly());

            routes.MapHttpAttributeRoutesInternal(configuration);
        }
        /// <summary>
        /// Scans the specified assemblies for all routes defined with AttributeRouting attributes,
        /// and applies configuration options against the routes found.
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="configurationAction">The initialization action that builds the configuration object</param>
        public static void MapHttpAttributeRoutes(this HttpRouteCollection routes, Action<HttpWebConfiguration> configurationAction)
        {
            var configuration = new HttpWebConfiguration();
            configurationAction.Invoke(configuration);

            routes.MapHttpAttributeRoutesInternal(configuration);
        }
 private static void MapHttpAttributeRoutesInternal(this HttpRouteCollection routes, HttpWebConfiguration configuration)
 {
     new RouteBuilder(configuration).BuildAllRoutes()
                                    .Cast<HttpAttributeRoute>()
                                    .ToList()
                                    .ForEach(r => routes.Add(r.RouteName, r));
 }
示例#4
0
        /// <summary>
        /// Scans the calling assembly for all routes defined with AttributeRouting attributes,
        /// using the default conventions.
        /// </summary>
        public static void MapHttpAttributeRoutes(this HttpRouteCollection routes)
        {
            var configuration = new HttpWebConfiguration();

            configuration.AddRoutesFromAssembly(Assembly.GetCallingAssembly());

            routes.MapHttpAttributeRoutesInternal(configuration);
        }
        /// <summary>
        /// Scans the specified assemblies for all routes defined with AttributeRouting attributes,
        /// and applies configuration options against the routes found.
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="configurationAction">The initialization action that builds the configuration object</param>
        public static void MapHttpAttributeRoutes(this HttpRouteCollection routes, Action<HttpWebConfiguration> configurationAction)
        {
            var configuration = new HttpWebConfiguration();
            configurationAction.Invoke(configuration);

            if (configuration.InMemory)
            {
                var newConfig = new HttpWebConfiguration(inMemory: true);
                configurationAction.Invoke(newConfig);
                routes.MapHttpAttributeRoutesInternal(newConfig);
            }
            else
            {
                routes.MapHttpAttributeRoutesInternal(configuration);
            }
        }
示例#6
0
        /// <summary>
        /// Scans the specified assemblies for all routes defined with AttributeRouting attributes,
        /// and applies configuration options against the routes found.
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="configurationAction">The initialization action that builds the configuration object</param>
        public static void MapHttpAttributeRoutes(this HttpRouteCollection routes, Action <HttpWebConfiguration> configurationAction)
        {
            var configuration = new HttpWebConfiguration();

            configurationAction.Invoke(configuration);

            if (configuration.InMemory)
            {
                var newConfig = new HttpWebConfiguration(inMemory: true);
                configurationAction.Invoke(newConfig);
                routes.MapHttpAttributeRoutesInternal(newConfig);
            }
            else
            {
                routes.MapHttpAttributeRoutesInternal(configuration);
            }
        }
        private static void MapHttpAttributeRoutesInternal(this HttpRouteCollection routes, HttpWebConfiguration configuration)
        {
            var generatedRoutes = new RouteBuilder(configuration).BuildAllRoutes().Cast<HttpAttributeRoute>().ToList();

            // If providing a custom IRouteHandler via config, add the routes to the RouteCollection.
            // Have to do this because the HttpRoutes do not support the functionality.
            var routeHandler = configuration.RouteHandlerFactory();
            if (routeHandler != null)
            {
                var mvcRoutes = RouteTable.Routes;
                generatedRoutes.ForEach(r =>
                {
                    var mvcRoute = mvcRoutes.MapHttpRoute(r.RouteName, r.Url, r.Defaults, r.Constraints, r.Handler);
                    mvcRoute.DataTokens = new RouteValueDictionary(r.DataTokens);
                    mvcRoute.RouteHandler = routeHandler;
                });
            }
            else
            {
                // Otherwise, add them to the HttpRouteCollection.
                generatedRoutes.ForEach(r => routes.Add(r.RouteName, r));
            }
        }
示例#8
0
 public void Issue191_default_web_config_inits_web_http_constraint_factory()
 {
     var inMemoryConfig = new HttpWebConfiguration();
     Assert.IsAssignableFrom<AttributeRouting.Web.Http.WebHost.Framework.RouteConstraintFactory>(inMemoryConfig.RouteConstraintFactory);
 }
示例#9
0
 public void Issue191_in_memory_web_config_inits_general_http_constraint_factory()
 {
     var inMemoryConfig = new HttpWebConfiguration(inMemory:true);
     Assert.IsAssignableFrom<AttributeRouting.Web.Http.Framework.RouteConstraintFactory>(inMemoryConfig.RouteConstraintFactory);
 }
示例#10
0
        public void GivenIHaveANewConfigurationObject()
        {
            _configuration = new Configuration();
            _configuration.InlineRouteConstraints.Add("color", typeof(EnumRouteConstraint<Color>));

            _httpConfiguration = new HttpWebConfiguration();
            _httpConfiguration.InlineRouteConstraints.Add("color", typeof(EnumRouteConstraint<Color>));
        }
 /// <summary>
 /// Scans the specified assemblies for all routes defined with AttributeRouting attributes,
 /// and applies configuration options against the routes found.
 /// </summary>
 /// <param name="routes"> </param>
 /// <param name="configuration">The configuration object</param>
 public static void MapHttpAttributeRoutes(this HttpRouteCollection routes, HttpWebConfiguration configuration)
 {
     routes.MapHttpAttributeRoutesInternal(configuration);
 }
示例#12
0
 private static void MapHttpAttributeRoutesInternal(this HttpRouteCollection routes, HttpWebConfiguration configuration)
 {
     new RouteBuilder(configuration).BuildAllRoutes()
     .Cast <HttpAttributeRoute>()
     .ToList()
     .ForEach(r => routes.Add(r.RouteName, r));
 }
示例#13
0
 /// <summary>
 /// Scans the specified assemblies for all routes defined with AttributeRouting attributes,
 /// and applies configuration options against the routes found.
 /// </summary>
 /// <param name="routes"> </param>
 /// <param name="configuration">The configuration object</param>
 public static void MapHttpAttributeRoutes(this HttpRouteCollection routes, HttpWebConfiguration configuration)
 {
     routes.MapHttpAttributeRoutesInternal(configuration);
 }
示例#14
0
 public void GivenIHaveANewConfigurationObject()
 {
     Configuration = null;
     HttpConfiguration = null;
 }