2012-02-04 38 views
9

tôi có mã trong global.axax tôi:Lâu đài Windsor không thể tìm thấy các trình cài đặt trong hội đồng

protected void Application_Start() 
{ 
    WindsorContainer = new WindsorContainer(); 
    WindsorContainer.Install(FromAssembly.InDirectory(new AssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath))); 
    ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(WindsorContainer.Kernel)); 
//... 
} 

Khi tôi gỡ lỗi global.asax, mã FromAssembly.InDirectory(newAssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath)) tìm tất cả các dự án dll của tôi (có 7 dll của). 3 trong số họ có thực hiện giao diện IWindsorInstaller, ví dụ:

class WindsorInstaller : IWindsorInstaller 
{ 
    public void Install(IWindsorContainer container, IConfigurationStore store) 
    { 
     var services = AllTypes.FromThisAssembly().Where(type => type.Name.EndsWith("Service")); 
     container.Register(services 
      .WithService.DefaultInterfaces() 
      .Configure(c => c.LifestyleTransient())); 
     container.Register(Component.For<ISession>().ImplementedBy<AspnetSession>(). 
      LifeStyle.Transient); 
     container.Register(Component.For<ICache>().ImplementedBy<AspnetCache>(). 
      LifeStyle.Transient); 
    } 
} 

Nhưng khi tôi đặt breakpoint, nó chỉ là 1 trình cài đặt gọi, 2 khác đã bỏ qua. Thật buồn cười, nhưng tôi có một dự án đang hoạt động khác với mã tôi đã sao chép.

Trả lời

14

Lớp trình cài đặt của bạn phải được công khai. Lớp trình cài đặt hiện tại của bạn không có bộ sửa đổi truy cập, do đó mặc định là internal - và không thể nhìn thấy được với Windsor. Tài liệu Castle chỉ định điều này tại đây: http://stw.castleproject.org/Windsor.Installers.ashx.

+0

Ôi trời ơi! Nó rất ngu ngốc sai lầm :) Cảm ơn! –

+4

Xảy ra cho tất cả chúng ta, mọi lúc :) – Marijn

Các vấn đề liên quan