现在,MAUI为我们提供了所有基本API的接口,我正试图在代码中使用它们,使其更易于测试。
在这段视频中,詹姆斯说我们应该将它们注册为:
builder.Services.AddSingleton<IGeolocation, GeolocationImplementation>();但是实现类现在都是内部的,所以不能以这种方式注册。
下面是正确的方法在类上使用当前或默认的道具吗?
builder.Services.AddSingleton<IGeolocation>(ctx => Geolocation.Default);
builder.Services.AddSingleton<IConnectivity>(ctx => Connectivity.Current);谢谢
发布于 2022-07-15 11:09:47
后来又发生了许多变化。当时詹姆斯的视频可能是正确的,但.NET MAUI中的实现后来发生了变化。
正如你所指出的,正确的方法是这样做:
builder.Services.AddSingleton<IGeolocation>(ctx => Geolocation.Default);
builder.Services.AddSingleton<IConnectivity>(ctx => Connectivity.Current);https://stackoverflow.com/questions/72992597
复制相似问题