Oakrey.Applications.ViewModels 2.0.3

dotnet add package Oakrey.Applications.ViewModels --version 2.0.3
                    
NuGet\Install-Package Oakrey.Applications.ViewModels -Version 2.0.3
                    
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="Oakrey.Applications.ViewModels" Version="2.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.ViewModels" Version="2.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Applications.ViewModels" />
                    
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 Oakrey.Applications.ViewModels --version 2.0.3
                    
#r "nuget: Oakrey.Applications.ViewModels, 2.0.3"
                    
#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.
#:package Oakrey.Applications.ViewModels@2.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Applications.ViewModels&version=2.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.ViewModels&version=2.0.3
                    
Install as a Cake Tool

Oakrey.Applications.ViewModels

A .NET library that removes manual DI wiring for ViewModels in MVVM applications. Mark a ViewModel class with the appropriate lifetime interface and call a single IServiceCollection extension method � the library discovers and registers all eligible types automatically via reflection.

Features

  • Reflection-based discovery of all IAutoConfigurable implementors at startup.
  • Four marker interfaces that control DI lifetime (see table below).
  • Single IServiceCollection extension method: RegisterAutoConfigurables.
  • No code generation, no attributes, no XML configuration.

Public API

// Marker interfaces � implement one to opt a ViewModel into auto-registration
IAutoConfigurable                 // transient (default)
ITransientAutoConfigurable        // transient (explicit)
IScopedAutoConfigurable           // scoped
ISingletonAutoConfigurable        // singleton

// IServiceCollection extension
services.RegisterAutoConfigurables();

// Discovery helper (optional, for diagnostics)
List<Type> types = ViewModelsConfiguration.GetAllAutoConfigurables;

Lifetime mapping

Interface DI lifetime
IAutoConfigurable Transient
ITransientAutoConfigurable Transient
IScopedAutoConfigurable Scoped
ISingletonAutoConfigurable Singleton

Architecture

classDiagram
    IAutoConfigurable <|-- ITransientAutoConfigurable
    IAutoConfigurable <|-- IScopedAutoConfigurable
    IAutoConfigurable <|-- ISingletonAutoConfigurable
    ViewModelsConfiguration ..> IAutoConfigurable : discovers
    ViewModelsConfiguration ..> IServiceCollection : registers into

Requirements

  • .NET 10 or higher
  • Microsoft.Extensions.DependencyInjection.Abstractions (10.0.x)
  • Oakrey.Reflection (2.0.x) � used internally for type discovery

Installation

.NET CLI

dotnet add package Oakrey.Applications.ViewModels

Package Manager Console

Install-Package Oakrey.Applications.ViewModels

NuGet Package Manager UI

Search for Oakrey.Applications.ViewModels in Visual Studio under Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

Usage

1. Mark your ViewModels

// Singleton � one instance for the application lifetime
internal sealed class MainViewModel : ObservableObject, ISingletonAutoConfigurable
{
    public MainViewModel(IMyService service) { }
}

// Transient � new instance every time it is resolved
internal class PromptViewModel : IAutoConfigurable
{
    public PromptViewModel(IUserPrompter prompter) { }
}

2. Register at startup

using Oakrey.Applications.ViewModels;

IServiceCollection services = new ServiceCollection();
services.RegisterAutoConfigurables(); // returns IServiceCollection � fluent chaining is supported

ServiceProvider provider = services.BuildServiceProvider();

3. Resolve normally

MainViewModel vm = provider.GetRequiredService<MainViewModel>();

4. Bind in XAML using ViewModelProvider

ViewModelProvider is a WPF MarkupExtension (shipped in Oakrey.Applications) that resolves a ViewModel from the DI container directly in XAML, without any code-behind assignment.

<Window
    xmlns:app="clr-namespace:Oakrey.Applications;assembly=Oakrey.Applications"
    DataContext="{app:ViewModelProvider viewModelType={x:Type local:MainViewModel}}">

For scoped ViewModels the provider creates a new IServiceScope tied to the FrameworkElement lifetime and disposes it when the element is unloaded.

Development notes

  • Type discovery uses Oakrey.Reflection and scans all loaded assemblies at the time RegisterAutoConfigurables is called. Ensure all relevant assemblies are loaded before calling the extension method.
  • The library is framework-agnostic at its core. WPF is not required; the package can be used in any .NET host that supports Microsoft.Extensions.DependencyInjection. ViewModelProvider is the only WPF-specific piece and lives in a separate Oakrey.Applications assembly.
  • GetAllAutoConfigurables returns a List<Type> and can be used at startup to log or audit which ViewModels were discovered.
  • RegisterAutoConfigurables returns IServiceCollection, so it can be chained fluently with other registration calls.

License

MIT. Copyright (c) Oakrey 2016-present.

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

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Oakrey.Applications.ViewModels:

Package Downloads
Oakrey.Applications.Settings

WPF-only (.NET 10 Windows) library providing ISettingsService with persistent and volatile typed key-value settings, SettingsBase for bindable ViewModelBase-derived settings classes, CallerMemberName key inference, built-in window bounds restore via RestoreBounds, and a one-call ConfigureSettingService DI extension.

Oakrey.Applications.About

A WPF/.NET library providing an About dialog with application name and version display, loaded assembly/module version listing, RTF EULA rendering, and a Report Issue form with log folder access.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.3 100 5/15/2026
2.0.2 124 3/13/2026
2.0.1 143 2/11/2026
2.0.0 449 11/18/2025
1.1.2 273 9/29/2025
1.1.1 239 9/8/2025
1.1.0 234 6/30/2025
1.0.0 216 6/30/2025