SingleFinite.Mvvm 0.0.26

dotnet add package SingleFinite.Mvvm --version 0.0.26
                    
NuGet\Install-Package SingleFinite.Mvvm -Version 0.0.26
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SingleFinite.Mvvm" Version="0.0.26" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SingleFinite.Mvvm" Version="0.0.26" />
                    
Directory.Packages.props
<PackageReference Include="SingleFinite.Mvvm" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SingleFinite.Mvvm --version 0.0.26
                    
#r "nuget: SingleFinite.Mvvm, 0.0.26"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=SingleFinite.Mvvm&version=0.0.26
                    
Install SingleFinite.Mvvm as a Cake Addin
#tool nuget:?package=SingleFinite.Mvvm&version=0.0.26
                    
Install SingleFinite.Mvvm as a Cake Tool

SingleFinite.Mvvm

SingleFinite.Mvvm is a Model-View-ViewModel library. It's built for .NET Core and contains interfaces, classes, and services that provide a solid foundation for building a modern MVVM .NET application.

Getting started

The following example illustrates a simple "hello world" style app that shows how to get something up and running after adding the SingleFinite.Mvvm nuget package as a dependency in your project.

To start, let's define a simple view model class that extends ViewModel:

// MyViewModel.cs
//

using SingleFinite.Mvvm;

namespace  MyApp;

public class MyViewModel : ViewModel
{
}

and a corresponding view class that implements IView and will be used with the view model defined above:

// MyView.cs
//

using SingleFinite.Mvvm;

namespace MyApp;

public class MyView(MyViewModel viewModel) : IView<MyViewModel>
{
    public MyViewModel ViewModel => viewModel;
}

Now that we have a view model and view defined we can configure an instance of IAppHost that will host our application state:

// Program.cs
//

using SingleFinite.Mvvm;

namespace MyApp;

var appHost = new AppHostBuilder()
    .AddViews(views => views.Add<MyViewModel, MyView>())
    .BuildAndStart();

As you can see above we use the AddViews method to register the MyViewModel and MyView types. Now when we want to display an instance of MyViewModel an instance of MyView will be used to display it.

â„šī¸ Note

There is an extension method for registering views that can be used to scan assemblies for ViewModel and IView types to register but we manually register them here for better clarity in the example.

Let's create a new instance of MyViewModel from the IAppHost instance we created above:

// Program.cs
//

// ...

var presentable = appHost.ServiceProvider.GetRequiredService<IPresentableItem>();
var viewModel = presentable.Set<MyViewModel>();

Console.WriteLine($"My ViewModel => {viewModel.GetType().FullName}");
Console.WriteLine($"My View => {presentable.Current.GetType().FullName}");

SingleFinite.MVVM is built on top of the Microsoft Dependency Injection library and the IAppHost object contains an IServiceProvider that holds all of the registered services. We get a new instance of IPresentableItem from the IServiceProvider which we use to create a new instance of our view model.

IPresentable services are used to create and manage the lifecycle of view models and their views. Both the view model and view will be created with a new dependency injection scope and will be injected with services as defined in their constructors. Normally you will use another platform specific library like SingleFinite.Mvvm.WinUI to manage the IAppHost instance and to present views for IPresentable based services.

Learn more

Check out the project Wiki for more detailed documentation on this library.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SingleFinite.Mvvm:

Package Downloads
SingleFinite.Mvvm.WinUI

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.26 152 4/3/2025
0.0.25 163 4/3/2025
0.0.24 156 4/2/2025
0.0.23 138 4/1/2025
0.0.22 143 4/1/2025
0.0.21 111 3/28/2025
0.0.20 136 3/21/2025
0.0.19 102 3/3/2025
0.0.18 93 2/26/2025
0.0.17 96 2/13/2025
0.0.16 105 2/12/2025
0.0.15 113 1/6/2025
0.0.14 109 1/2/2025
0.0.13 103 12/24/2024
0.0.12 90 12/21/2024
0.0.11 99 12/18/2024
0.0.10 102 12/15/2024
0.0.9 101 12/15/2024
0.0.8 102 12/3/2024
0.0.7 98 11/26/2024
0.0.6 100 11/26/2024
0.0.5 100 11/23/2024
0.0.4 101 11/22/2024
0.0.3 102 11/19/2024
0.0.2 103 11/16/2024
0.0.1 113 11/11/2024