我試圖在我使用一個商業ORM的小項目上使用IoC。添加僅由接口表示的對象到ORM生成的實體集合
在我的實體'項目'中有'用戶'實體的集合。當我將接口傳遞給方法時,我無法將eobject添加到'User'實體的集合中,因爲它由一些ORM EntityCollection類表示。
例子:
//'this' is a partial class to the modeled Entity<int>
public void AddToCollection(IUser user)
{
this.Users.Add(user); //this.Users is type of EntityCollection.
}
我在這裏看到了兩種可能性,我不知道哪一個是最好的做法。
- 更改EntityCollection到IEnumerable的(這是不可能的)
- 演員IUSER到用戶
,或者可以我會完全錯誤的室內用的方式IoC的,什麼是最好的做法嗎?
By IoC do you mean you're using dependency injection and a container?如果你正在通過你的ORM加載和保存'User'實例,那麼爲什麼你有一個'IUser'接口,以及它如何與使用DI容器相關,目前還不清楚。 – Lee 2012-07-21 15:50:28