Attribute based routing registration with Service API

Vote:
 

EPiServer Service API integration module provides a way to "delay" attribute based routing registartion and delegate that to some external code by adding following key to :

However this seems not to work properly. Tried following solutions:

Added this code to following places:

GlobalConfiguration.Configure(config => config.MapHttpAttributeRoutes());



a) Added to Application_Start()

b) Added to overridden Global.RegisterRoutes()

c) Created initializable module with dependency to EPiServer.ServiceApi.IntegrationInitialization

Called directly GlobalConfiguration.Configuration.MapHttpAttributeRoutes() and then GlobalConfiguration.Configuration.EnsureInitialized().

None of these seems to have any effect.

ServiceApi services ends with error message like:

[InvalidOperationException: The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.]
   System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() +101
   System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) +63
   System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext) +107
   System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +233
#139926
Oct 09, 2015 20:02
Vote:
 

I got it to work like this.  You need to make sure you call it before Configure.  Unfortunatley HttpConfiguration does not like when there are multiple => configure() called.

using System;
using System.Linq;
using System.Web.Http;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;

namespace ServiceApi.Test.Business
{
    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Framework.FrameworkInitialization))]
    public class TestAttributeRouting : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
            
        }

        public void Preload(string[] parameters) { }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
}

The main reason we added this was becasue if other third party libraries were calling MapAttirbutes then there would be an error.  If you are just using attibute routing then letting ServiceApi map them should be sufficient.

#140228
Oct 13, 2015 22:37
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.