1
這裏的情況是:國際奧委會在複雜的環境中
ICategorized
所使用的ICategoryService
管理類別。
public interface ICategorized
{
ICategory Category { get; set; }
}
然後一些類實現ICategorized
。
public class Cart : ICategorized
{
...
ICategory Category {
get {
return _categoryService.GetItemCategory(...)
}
set {
_categoryService.SetCategoryForItem(...);
};
}
...
}
那麼,設置_categoryService
實現的最佳解決方案是什麼? 通過構造函數或屬性注入?
構造函數的使用可能導致非常複雜的構造像
public class Cart : ICategorized. ITagged, ISecured, IMediaSupport {
public Cart(ICategoryService cs, ITagService ts, ISecurityService ss, IMediaService ms) {...}
...
}
我懷疑這是一個不錯的設計。有任何想法嗎?
你會有什麼建議嗎? 我可以給ICServiceService負責CartService,但在這種情況下,我不能使用Lazy加載。像
public class CartService : ICartService {
public CartService(ICategoryService cs) {...}
...
}
+1會添加一個答案,但是總結得非常好。 – eglasius 2009-11-11 16:53:45