[英]how to install dependencies with castle windsor in a layered architecture
我在MVC項目中將Castle Windsor用於ioc。
我的架構基本上是Web-> Services-> Data
控制器將服務作為依賴項。 服務具有存儲庫作為數據層中的依賴項。
我的Web層沒有對數據層的引用。 我的問題是我試圖注冊我的存儲庫,這是我的服務的依賴項。 如果我在服務層中有一個單獨的容器來注冊存儲庫,我應該如何引導它?
否則我可能會以錯誤的方式進行操作。
這個怎么樣。 缺點是您需要對存儲庫dll的名稱進行硬編碼,但是您始終可以將其移動到web.config等,這樣會更加簡潔。
IWindsorContainer container = new WindsorContainer();
// Register repositories
_container.Register(
AllTypes.Pick()
.FromAssemblyNamed("MyDataLayerAssembly")
.WithService
.DefaultInterface());
// Register services
_container.Register(
AllTypes.Pick()
.FromAssemblyNamed(typeof(ISomeService).Assembly.GetName().Name)
.WithService
.DefaultInterface());
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
但是,您可能只需要精確調整Register()
方法中傳遞的內容以適合您的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.