C# 无法注册数据服务Prism Xamarin表单
我正在尝试注册我的服务,以便将参数发送到下一个ViewModel 这是我的App.Xaml.csC# 无法注册数据服务Prism Xamarin表单,c#,xamarin,xamarin.forms,prism,C#,Xamarin,Xamarin.forms,Prism,我正在尝试注册我的服务,以便将参数发送到下一个ViewModel 这是我的App.Xaml.cs protected override void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.RegisterForNavigation<NavigationPage>(); containerRegistry.RegisterForNavigati
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<View.MainPage, MainPageViewModel>();
containerRegistry.Register<IService, Service>();
}
我的界面:
public interface IService
{
Task<List<TodoItem>> DataAsync();
}
获取数据的我的服务类:
public class Service
{
public List<TodoItem> TodoList { get; private set; }
HttpClient client;
Service()
{
client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;
}
public async Task<List<TodoItem>> DataAsync()
{
TodoList = new List<TodoItem>();
var uri = new Uri(string.Format(Constants.RestUrl, string.Empty));
try
{
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
TodoList = JsonConvert.DeserializeObject<List<TodoItem>>(content);
Debug.WriteLine(content);
}
}
catch (Exception ex)
{
Debug.WriteLine(@"ERROR {0}", ex.Message);
}
return TodoList;
}
}
我从这行im App.Xaml.cs获取错误:
containerRegistry.Register<IService, Service>();
错误消息:
错误CS0311:类型“MyApp.Services.Service”不能用作泛型类型或方法“IContainerRegistryExtensions.RegisterContainerRegistry”中的类型参数“TTo”。没有从“MyApp.Services.Service”到“MyApp.Services.IService”的隐式引用转换。CS0311 MyApp您的服务类需要声明它实现了iSeries
public class Service : IService