2012-09-11 152 views
1

我剛開始探索ReactiveUI,但遇到一些問題。找不到ICreatesObservableForProperty

在ReactiveObject,我儘量讓可觀察的基礎上的屬性...

public class StudentListViewModel : ReactiveObject, IStudentListViewModel 
{ 
    public StudentListViewModel() 
    { 
     var observable = this.ObservableForProperty(x => x.SearchQuery); 
    } 

    string _SearchQuery; 
    public string SearchQuery 
    { 
     get { return _SearchQuery; } 
     set { this.RaiseAndSetIfChanged(x => x.SearchQuery, value); } 
    } 
} 

...這導致了以下錯誤:

Couldn't find a ICreatesObservableForProperty for MyApplication.ViewModels.StudentListViewModel. This should never happen, your service locator is probably broken.

我已經使用Ninject爲DI容器,並試圖像這樣告訴ReactiveUI:

class Bootstrapper : IBootstrapper 
{ 
    public Bootstrapper() 
    { 
     Kernel = new StandardKernel(); 
     Kernel.Bind<IBootstrapper>().ToConstant(this); 
     Kernel.Bind<IScreen>().ToConstant(this); 
     Kernel.Bind<IViewFor<StudentListViewModel>>().To<StudentListView>(); 

     Router = new RoutingState(); 

     RxApp.ConfigureServiceLocator(
      (type, key) => Kernel.Get(type, key), 
      (type, key) => Kernel.GetAll(type, key), 
      (from, type, key) => 
       { 
        var binding = Kernel.Bind(from).To(type); 
        if (key != null) 
         binding.Named(key); 
       } 
      ); 
    } 
} 

有沒有人看到p這裏有什麼?

回答

1

你切換 '從' 和 '關鍵':

RxApp.ConfigureServiceLocator(
     (type, key) => Kernel.Get(type, key), 
     (type, key) => Kernel.GetAll(type, key), 
     (from, type, key) => 
      { 
       var binding = Kernel.Bind(type /*this was from*/).To(from /*ditto*/); 
       if (key != null) 
        binding.Named(key); 
      } 
     ); 
+0

不錯的漁獲物。謝謝。 – Vegar

+0

這很容易做到,我需要設法讓錯誤發生時更明顯 –