我想實現自動註冊爲我的存儲庫,它遵循這一慣例:城堡溫莎註冊組件通過公約
- 庫實現
IRepository
- 有它實現
IRepository
一個抽象類,例如:UserRepository
- 實際執行這一抽象類的名稱結尾,例如:
EntityFrameworkUserRepository
我想用城堡將依賴關係注入到我的控制器中。
public LinkService(LinkRepository linkRepository)
{
if (linkRepository == null)
{
throw new ArgumentNullException("linkRepository");
}
this.linkRepository = linkRepository;
}
我該如何映射「它實現組件IRepository
」到
container.Register(Component.For<LinkRepository>().ImplementedBy<EntityFrameworkLinkRepository>())
這樣的事情,只能自動註冊,所以我不「它具有相同的名稱作爲組件最終實現」」不用爲了在此處手動每創建一個新的
[Windsor中的請求程序基於參數名稱註冊組件]的可能重複(http://stackoverflow.com/questions/9339840/register-component-based-on-parameter-name-on-requestor-in-windsor) – 2012-02-26 19:22:59
我認爲使用約定來設置容器是個好主意。但是你應該考慮爲什麼你需要存儲庫來隱藏你的ORM。艾恩德寫了很多關於這個。其中一個帖子:http://ayende.com/blog/3955/repository-is-the-new-singleton – Allrameest 2012-02-26 19:55:25