Настройка инверсии управления (IoC) в ASP .NET MVC с Castle Windsor

I ' Я перехожу к Pro ASP Сандерсона. NET MVC Framework, а в главе 4 он обсуждает Создание настраиваемой фабрики контроллеров , и кажется, что исходный метод AddComponentLifeStyle или AddComponentWithLifeStyle , используемый для регистрации контроллеров, устарел. now:

public class WindsorControllerFactory : DefaultControllerFactory
{
    IWindsorContainer container;

    public WindsorControllerFactory()
    {
        container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));

        // register all the controller types as transient
        var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
                              where typeof(IController).IsAssignableFrom(t)
                              select t;

        //[Obsolete("Use Register(Component.For().ImplementedBy().Named(key).Lifestyle.Is(lifestyle)) instead.")]
        //IWindsorContainer AddComponentLifeStyle(string key, LifestyleType lifestyle) where T : class;
        foreach (Type t in controllerTypes)
        {
            container.Register(Component.For().ImplementedBy().Named(t.FullName).LifeStyle.Is(LifestyleType.Transient));
        }
    }

    // Constructs the controller instance needed to service each request
    protected override IController GetControllerInstance(Type controllerType)
    {
        return (IController)container.Resolve(controllerType);
    }
}

Новое предложение - использовать Register (Component.For () .ImplementedBy () .Named (key) .Lifestyle.Is (lifestyle)) , но я не могу понять, как представить реализующий тип контроллера в методе ImplementedBy ??> () . Я пробовал ImplementedBy () и ImplementedBy () , но не могу найти подходящий способ передать тип реализации. как я могу знать?

6
задан Martin Buberl 26 February 2011 в 02:16
поделиться