Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483319
  • 博文数量: 112
  • 博客积分: 5696
  • 博客等级: 大校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-17 09:58
文章分类

全部博文(112)

文章存档

2011年(22)

2010年(28)

2009年(21)

2008年(41)

分类: WINDOWS

2010-08-12 23:36:39

  public class WindsorControllerFactory : DefaultControllerFactory
          {
               WindsorContainer container;

               // The constructor:
               // 1. Sets up a new IoC container
               // 2. Registers all components specified in web.config
               // 3. Registers all controller types as components
               public WindsorControllerFactory()
               {
                    // Instantiate a container, taking configuration from web.config
                    container = new WindsorContainer(
                                        new XmlInterpreter(new ConfigResource("castle"))
                                   );

                    // Also register all the controller types as transient
                    var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
                                               where typeof(IController).IsAssignableFrom(t)
                                               select t;
                    foreach(Type t in controllerTypes)
                         container.AddComponentWithLifestyle(t.FullName, t,
                                                                       LifestyleType.Transient);
               }

               // Constructs the controller instance needed to service each request
               protected override IController GetControllerInstance(Type controllerType)
               {
                    return (IController)container.Resolve(controllerType);
               }
          } 
阅读(775) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~