WindsorControllerFactory, . , 404s, (.. - "/garbageblahblah" ), . , Reflector , factory URL-.
, Mvc . CreateController, GetControllerInstance(), Mvc, ./ .
My CastleWindsorControllerFactory:
public class CastleWindsorControllerFactory : DefaultControllerFactory
{
WindsorContainer _container;
public CastleWindsorControllerFactory()
{
_container =
new WindsorContainer(
new XmlInterpreter(
new ConfigResource("castle")
)
);
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);
ControllerBuilder.Current.SetControllerFactory(
new CastleWindsorControllerFactory());
}
, . , ComponentFactory. Singleton , .
, ComponentFactory() . , , . : me -at- eduncan911.com