我有以下。鑄造通用接口
public interface IMyService<T>
where T: BaseModelType
{
Process(T input);
}
public class BaseModelType
{
...some property
}
public class SomeClass : BaseModelType
{
...some properties
}
public ServiceImpl : IMyService<SomeClass>
{
...the properties
}
然後,我有一個統一容器,我註冊了通用接口的所有實現。我希望能夠使用unitycontainer的解析方法來獲取接口,然後對它做一些工作。在當我想用解決方法我在運行時
new UnityContainer.Resolve(myTypeVar)
我可以以某種方式投類型的時候這是
IMyService<BaseModelType> value = new UnityContainer.Resolve(myTypeVar) //want to cast it here from object.
,這樣我可以調用過程方法的接口定義。
我想補充這一點,我想用一個控制器動作打造保存所有的步驟建立在MVC的嚮導。該步驟正在使用接口來處理它所需的內容,然後它將返回下一步,具體取決於第一步中輸入的內容。 – Captain0