我刚开始探索ReactiveUI,但有一些问题。
在ReactiveObject中,我尝试根据属性创建一个observable ......
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); }
}
}
...导致以下错误:
无法找到ICreatesObservableForProperty MyApplication.ViewModels.StudentListViewModel。这绝不应该 发生了,您的服务定位器可能已损坏。
我使用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);
}
);
}
}
有人在这看到问题吗?
答案 0 :(得分:1)
您切换了'from'和'key':
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);
}
);