You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Standard 2.0核心项目中MvvmCross SQLite插件选型咨询

MvvmCross SQLite 现状与.NET Standard 2.0 选型方案

Great question—this is a common pain point when working with MvvmCross and .NET Standard, especially since the old plugin ecosystem has shifted significantly over the years. Let’s break down the current landscape and your best options:

First, the context on deprecated plugins

The Cirrious.MvvmCross.Plugins.Sqlite package you’re searching for is completely deprecated—MvvmCross stopped maintaining these old "Cirrious-branded" plugins back around version 5, which is why it doesn’t show up in NuGet anymore. Similarly, the sqlite-pcl-net mentioned in v5 docs was a transitional package that never gained full MvvmCross integration, so it’s not a viable long-term solution.

Current MvvmCross + SQLite approach

MvvmCross no longer ships with official SQLite plugins. Instead, the team recommends integrating standard, cross-platform SQLite libraries via MvvmCross’s built-in dependency injection (DI) system. This gives you more flexibility and ensures compatibility with .NET Standard 2.0.

Top options for your .NET Standard 2.0 project

Here are the two most reliable, widely used solutions:

  • Primary Recommendation: sqlite-net-pcl + MvvmCross DI
    This is the de facto standard for SQLite with MvvmCross today. The sqlite-net-pcl package (maintained by Frank Krueger) is fully compatible with .NET Standard 2.0, offers a lightweight ORM, and plays nicely with MvvmCross’s MVVM pattern.

    1. Install the NuGet package:
      Install-Package sqlite-net-pcl
      
    2. Register your SQLite connection in MvvmCross’s Setup class to make it available via DI:
      protected override void InitializeFirstChance()
      {
          base.InitializeFirstChance();
          // Adjust the database path based on your target platform (this works for desktop/mobile)
          var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "your_app.db3");
          Mvx.IoCProvider.RegisterSingleton<ISQLiteConnection>(() => new SQLiteConnection(dbPath));
      }
      
    3. Inject the connection into your ViewModels or services via constructor injection, just like any other MvvmCross dependency:
      public class MyViewModel : MvxViewModel
      {
          private readonly ISQLiteConnection _db;
      
          public MyViewModel(ISQLiteConnection db)
          {
              _db = db;
              // Use _db to create tables, query data, etc.
          }
      }
      
  • Alternative: Microsoft.Data.Sqlite + MvvmCross
    If you prefer a more ADO.NET-style approach or need deeper integration with Microsoft’s ecosystem, Microsoft.Data.Sqlite is a solid choice. It also supports .NET Standard 2.0 and works well with MvvmCross’s DI.

    1. Install the NuGet package:
      Install-Package Microsoft.Data.Sqlite
      
    2. Register the connection in Setup:
      protected override void InitializeFirstChance()
      {
          base.InitializeFirstChance();
          var connectionString = new SqliteConnectionStringBuilder 
          { 
              DataSource = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "your_app.db3") 
          }.ToString();
          Mvx.IoCProvider.RegisterSingleton<SqliteConnection>(() => new SqliteConnection(connectionString));
      }
      
    3. Inject and use it in your ViewModels/services as needed—this is ideal if you’re writing lots of raw SQL queries.

Why to avoid other "SQLite-PCL" packages

Most generic SQLite-PCL packages aren’t optimized for MvvmCross, and many lack proper .NET Standard support or active maintenance. Stick to the two options above for stability and compatibility.

In short: MvvmCross has moved away from proprietary plugins to embrace standard libraries, which is great for .NET Standard projects. sqlite-net-pcl is your best bet for most MVVM scenarios, thanks to its ORM features and seamless DI integration.

内容的提问来源于stack exchange,提问作者Agat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:24:49