현재 Mvvm Light의 IoC 컨테이너에 문제가 있습니다. 인터페이스가 IDataService
인데, 이는 두 클래스 (DataService1
및 DataService2
)로 구현됩니다. 또한 많은 종속성을 가진 MainViewModel
클래스가 있는데 하나는 IDataService
입니다.MVVMLight의 IoC 컨테이너 - 구체적인 구현을 지정된 요소로 전달하는 방법은 무엇입니까?
요점은 MainViewModel
에 DataService2
을 입력하고 싶습니다. 어떻게해야합니까? 나는 "키"그 같은 IDataService
과 MainViewModel
의 두 경우에 시도했다 :
class MainViewModel
{
// MainViewModel has many dependencies,
public MainViewModel(X x, Y y, Z z, M m, N n, IDataService dataService) { }
}
(...)
SimpleIoc.Default.Register<IDataService>(() => new DataService1(), "A");
SimpleIoc.Default.Register<IDataService>(() => new DataService2(), "B");
(...)
var viewModel = SimpleIoc.Default.GetInstance<MainViewModel>("B"); // Runtime exception
그러나 나는 기본적으로 MainViewModel
가 해결 될 수 없다는 런타임 예외를 얻을 - 내가 이해 한 것과을 나는 경우 을MainViewModel
("B")으로 수정하려는 경우 모든 종속성을 키 설정해야합니다. 이것은 내가 원하는 것이 아니며, 하나만 제외하고는 디폴트 종속성이있는 MainViewModel
을 해결하려고합니다.
어떻게하면됩니까? 나는 분명히 뭔가를 놓치고있다. 모든 도움을 미리 감사드립니다.
정확한 예외 메시지는 무엇입니까? – romanoza
http://stackoverflow.com/questions/19301891/mvvmlight-simpleioc-and-multiple-concrete-implementations –
@RomanKo ActivationException이 발생합니다. 추가 정보 : 키가없는 캐시에 유형이 없습니다. ViewModels.MainViewModel – Malutek