【发布时间】:2015-02-13 08:52:47
【问题描述】:
我有一个使用 MVVM Light 的 wpf 应用程序。我有两个类和接口:
public interface ICrud{
//
}
public class CrudDAO : ICrud{
//
}
public class CrudEF : ICrud{
//
}
我有两个视图模型:
public class CrudDAOVM {
public ICrud icrud;
public CrudDAOVM (ICrud _icrud)
{
icrud = _icrud;
}
}
public class CrudEFVM {
public ICrud icrud;
public CrudEFVM (ICrud _icrud)
{
icrud = _icrud;
}
}
我想使用 SimpleIoc 来注入依赖项。所以我在 ViewModelLocator 中添加了这段代码:
SimpleIoc.Default.Register<ICrud , CrudDAO >(); //I'd like to add the condition here
SimpleIoc.Default.Register<ICrud , CrudEF >();//I'd like to add the condition here
我想添加一个条件,指定inside CrudVMDAO, the implementation of ICrud is CrudDAO, and inside CrudVMEF, the implementation of ICrud is CrudEF
是否可以使用SimpleIoc 做到这一点?
【问题讨论】:
标签: c# wpf mvvm dependency-injection mvvm-light