Xamarin 中的 [assembly: Dependency()] 是什么?

Sta*_*ord 4 .net c# android xamarin xamarin.forms

我是 Xamarin 的新手。我正在学习一个教程,在那

[assembly: Dependency(typeof())]
Run Code Online (Sandbox Code Playgroud)

被使用。没看懂这行代码的作用是什么。请解释它的功能。

以下是代码。

[assembly: Dependency(typeof(SQLiteAndroid))]

namespace XamTestThree.Droid.Data {
    public class SQLiteAndroid :ISQLite{
        public SQLiteAndroid() { }
        public SQLite.SQLiteConnection GetConnection()
        {
            var sqlLiteFileName = "TestDB.db3";
            string documentPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var path = Path.Combine(documentPath, sqlLiteFileName);
            var conn = new SQLite.SQLiteConnection(path);
            return conn; 

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Arv*_*iya 5

这称为注册。

平台实现必须使用 注册DependencyService,以便Xamarin.Forms可以在运行时定位它们。

这通常与 一起执行DependencyAttribute,这表明指定的类型提供了 的实现interface。

有关详细信息,请访问DependencyServices - Microsoft 文档。