views:

22

answers:

1

I am trying to abstract out the route registraion process out of global.asax into a bootstrapper. My class looks like:

public class RegisterRoutes : IBootstrapperTask
{
    private readonly RouteCollection routes;

    public RegisterRoutes(RouteCollection routes)
    {
        this.routes = routes;
    }

    public RegisterRoutes() : this(RouteTable.Routes)
    {
    }

    public void Execute()
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
        );
    }
}

My global.asax looks like:

protected void Application_Start()
{
    Bootstrapper.Run();
}

My simplified bootstrapper looks like:

public static class Bootstrapper
{
    static Bootstrapper()
    {
        // wires up the container
    }

    public static void Run()
    {
        container.ResolveAll<IBootstrapperTask>().Each(t => t.Execute());
    }
}

The container resolver fine but when I try to execute the tasks I get: InvalidOperationException - The type VirtualPathProvider cannot be constructed. You must configure the container to supply this value.

Any feedback would be appreciated.

Thanks

A: 

I think unity is trying to use this constructor:

public RegisterRoutes(RouteCollection routes)

If that's the case you need to either explicitly configure it to use the parameter less constructor or remove the constructor that has the routes parameter.

ps. I can't claim the above to be accurate, since I'm basing it in my expectations of unity to behave similar than StructureMap in the that scenario.

eglasius
You are correct! Once I tried either approach it worked. Thanks.
Thomas