Reactiveui Splat:Locator.Current vs Locator.CurrentMutable
因此,Splat提供了两种检索服务的方法:Reactiveui Splat:Locator.Current vs Locator.CurrentMutable,reactiveui,splat,Reactiveui,Splat,因此,Splat提供了两种检索服务的方法: var s1 = Locator.Current.GetService<IMyService>(); var s2 = Locator.CurrentMutable.GetService<IMyService>(); var s1=Locator.Current.GetService(); var s2=Locator.CurrentMutable.GetService(); 不清楚我们应该用哪种方式 那么这两者之间的区别是
var s1 = Locator.Current.GetService<IMyService>();
var s2 = Locator.CurrentMutable.GetService<IMyService>();
var s1=Locator.Current.GetService();
var s2=Locator.CurrentMutable.GetService();
不清楚我们应该用哪种方式
那么这两者之间的区别是什么呢?我们应该用哪一个?我们应该避免哪一个?定位器。当前的是只读版本,除非您正在注册服务,否则应使用该版本。 定位器。CurrentMutable是读/写版本,仅应在注册服务时使用 它们都指向相同的定位器,只是基于您使用的变量的用例 基本上:
- 使用CurrentMutable注册服务
- 在需要检索时使用Current