Why is Castle Windsor trying to resolve my Content and Scripts folder as a controller?

I created an ASP.NET MVC application and am trying to use Castle Windsor as my IOC

However, when the controllers try to solve the problem, I get "Content" and "Scripts" in the "controllerName" parameter in the method CreateController(RequestContext requestContext, string controllerName). Needless to say, these are not controllers. They are apparently website folders.

Why is he trying to register them as controllers?

How to ignore these folders?

thanks

exception from WindsorControllerFactory

Due to the fact that I cannot publish the image, I have to describe it - it just says

'Content controller not found'

Global.asax.cs

public static IIocContainer Ioc;

            protected void Application_Start()
            {
                InitialiseIocContainer();
                RegisterViewEngine(ViewEngines.Engines);
                RegisterRoutes(RouteTable.Routes);
                StartProfiling();
            }


private void InitialiseIocContainer()
        {
            IWindsorContainer _container = new WindsorContainer();

            var controllerTypes = typeof (GidgetController).Assembly.GetTypes();
            foreach (var controllerType in controllerTypes.Where((t=>typeof(IController).IsAssignableFrom(t))))
            {
                _container.AddComponentLifeStyle(controllerType.Name.ToLower(), controllerType, LifestyleType.Transient);   
            }


            _container.AddComponent("a",typeof(IGidgetService), typeof(GidgetService));
            _container.AddComponent("b",typeof(IGidgetRepository), typeof(GidgetRepository));
            _container.AddComponent("c",typeof(IGidgetValidator), typeof(GidgetValidator));


            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_container));

        }

windsorControllerFactory.cs

public IController CreateController(RequestContext requestContext, string controllerName)
        {
            try
            {
                controllerName = controllerName.ToLower() + "controller";
                var controller = _container.Resolve<IController>(controllerName);
                return controller;
            }
            catch (ComponentNotFoundException)
            {
                throw new HttpException(404, string.Format("The {0} controller was not found", controllerName));

            }

        }
+2
2

MVCContrib.

, Windsor ASP.NET MVC, factory .

+1

WindsorControllerFactory, . , 404s, (.. - "/garbageblahblah" ), . , Reflector , factory URL-.

, Mvc . CreateController, GetControllerInstance(), Mvc, ./ .

My CastleWindsorControllerFactory:

/// <summary>
/// Represents a special controller factory.
/// </summary>
public class CastleWindsorControllerFactory : DefaultControllerFactory
{
    WindsorContainer _container;

    public CastleWindsorControllerFactory()
    {
        // register all controllers from the calling assembly.
        // (e.g. the mvc site calling this factory)
        //
        _container =
            new WindsorContainer(
                new XmlInterpreter(
                    new ConfigResource("castle")
                )
            );

        // change this to Assembly.GetAssembly() if used directly from
        // your MVC website.  The code below is for when this class
        // exists in a seperate assembly.
        //
        var controllers =
            from t in Assembly.GetCallingAssembly().GetTypes()
            where typeof(IController).IsAssignableFrom(t)
            select t;

        foreach (Type t in controllers)
            _container.AddComponentLifeStyle(
                t.FullName, t, LifestyleType.Transient); 
    }

    protected override IController GetControllerInstance(Type controllerType)
    {
        if (controllerType == null)
        {
            throw new HttpException(
                0x194
                , string.Format(
                    CultureInfo.CurrentUICulture
                    , "Controller Not Found"
                    , new object[] {
                        this.RequestContext.HttpContext.Request.Path }));
        }
        if (false == typeof(IController).IsAssignableFrom(controllerType))
        {
            throw new ArgumentException(
                string.Format(
                    CultureInfo.CurrentUICulture
                    , "Type does not sub-class the controller base"
                    , new object[] { controllerType }), "controllerType");
        }

        return 
            (IController) _container.Resolve(controllerType);
    }
}

Globals.asax.cs , (, , ! CastleWindsorControllerFactor ).

protected void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);

    // custom controller factory that uses Windsor
    ControllerBuilder.Current.SetControllerFactory(
        new CastleWindsorControllerFactory());

    // Uncomment to debug routes
    //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}

, . , ComponentFactory. Singleton , .

, ComponentFactory() . , , . : me -at- eduncan911.com

+1

All Articles