Я пытаюсь зарегистрировать свой Сервис, чтобы я мог отправить параметр следующей ViewModel.
Это мой App.Xaml.cs
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» нельзя использовать в качестве параметра типа «TTo» в универсальном типе или методе «IContainerRegistryExtensions.Register (IContainerRegistry)».Не существует неявного преобразования ссылок из MyApp.Services.Service в MyApp.Services.IService.(CS0311) (MyApp)