Xamarin Abhängigkeit-Dienst-Problem

In Xamarin Forms habe ich eine Lösung wie diese:

Solution
 |- Libraries
 |   |- IInterface.cs
 |   |- Etc.
 |
 |- Libraries.iOS
 |   |- Interface.cs
 |   |- Etc.
 |
 |- Forms.App
 |   |- App.cs
 |   |- Etc.
 |
 |- Forms.App.iOS
 |   |- Etc.
  • Formen.App.iOS Verweise Bibliotheken.iOS
  • Formen.App Referenzen Bibliotheken
  • Bibliotheken.iOS Verweise Bibliotheken
  • Formen.App.iOS-Verweise Formen.App

IInterface.cs

namespace a
{
  public interface IInterface
  {
    void Function ();
  }
}

- Schnittstelle.cs

[assembly: Xamarin.Forms.Dependency(typeof(a.Interface))]
namespace a
{
  public class Interface : IInterface
  {
    public void Function ()
    {
      return;
    }
  }
}

App.cs

namespace a
{
  public class App
  {
    public static Page GetMainPage ()
    {
      var inter = DependencyService.Get<IInterface> (); //This is always null.
      return new ContentPage { 
        Content = new Label {
        Text = "Hello, Forms!",
        VerticalOptions = LayoutOptions.CenterAndExpand,
        HorizontalOptions = LayoutOptions.CenterAndExpand,
        },
      };
    }
  }
}

Wie kann ich die Abhängigkeit Dienst suchen, meine Interface-Implementierung?
Ich muss Ihnen in einem separaten Projekt, denn ich muss die gleichen Implementierungen in verschiedenen Projekten.

InformationsquelleAutor BisaZ | 2014-11-27
Schreibe einen Kommentar