Мне нужен DependencyService для использования определенных c android функций.
После отладки я вижу, что DependencyService - это вызов, приложение тоже вызывается.
Почему DependencyService.Get<T>()
вызов App()
?
IMyService.cs
namespace SampleM3Scan.MobileApp.Services
{
public interface IMyService
{
}
}
MyService.cs
using Android.Content;
using App1.MobileApp.Droid;
using App1.MobileApp.Services;
using Xamarin.Forms;
[assembly: Dependency(typeof(MyService))]
namespace App1.MobileApp.Droid
{
internal class MyService : IMyService
{
private readonly MyReceiver _myReceiver = new MyReceiver();
public class MyReceiver : BroadcastReceiver
{
private readonly App app = new App();
public override void OnReceive(Context context, Intent intent)
{
MessagingCenter.Send(app ,"item", intent.GetStringExtra("item"));
}
}
}
}
MainPage.xaml. CS
using System.ComponentModel;
using App1.MobileApp.Pages.Base;
using App1.MobileApp.Services;
namespace App1.MobileApp.Pages.Main
{
[DesignTimeVisible(false)]
public partial class MainPage : PageBase
{
public MainPage()
{
InitializeComponent();
var myService = DependencyService.Get<IMyService>();
BindingContext = new MainPageViewModel(myService);
}
}
}