Oakrey.Applications.ViewModels 8.0.0

dotnet add package Oakrey.Applications.ViewModels --version 8.0.0
                    
NuGet\Install-Package Oakrey.Applications.ViewModels -Version 8.0.0
                    
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="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.ViewModels" Version="8.0.0" />
                    
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 8.0.0
                    
#r "nuget: Oakrey.Applications.ViewModels, 8.0.0"
                    
#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@8.0.0
                    
#: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=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.ViewModels&version=8.0.0
                    
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

  • Deterministic discovery of concrete, closed 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 11 or higher
  • Microsoft.Extensions.DependencyInjection.Abstractions (10.0.x)
  • Oakrey.Log.Abstractions (3.0.x) - registration diagnostics
  • 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.
  • Existing registrations are preserved, and duplicate automatic registrations are skipped.
  • Types implementing multiple explicit lifetime markers fail fast instead of silently selecting a lifetime.
  • Registration logs contain type names and lifetimes only; no resolved instances or application data are logged.

License

MIT. Copyright (c) Oakrey 2016-present.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

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

Package Downloads
Oakrey.Applications.Base

A foundational .NET library for building modular WPF applications. Provides application lifecycle management, MVVM ViewModel resolution, structured logging, telemetry, and sequential or parallel service preloading with full unhandled-exception coverage.

Oakrey.Applications.Settings

WPF-only (.NET 11 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 explicit dependency-injection integration.

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.

Oakrey.Applications.ControlObjects

A .NET WPF library for building interactive, validated control objects. Provides a base class hierarchy for reactive sending objects, enable/disable and timer-driven variants, cancelable async operations, device abstraction, multi-key gesture support, and observable collections with automatic JSON persistence.

Oakrey.Applications.Dashboards.Abstractions

Shared generic dashboard models, services, collections, and WPF view-model infrastructure for Oakrey CAN and LIN applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.0 53 11/15/2026
7.0.1 187 9/21/2026
7.0.0 298 7/20/2026
2.0.5 164 7/3/2026
2.0.4 203 5/22/2026
2.0.3 161 5/15/2026
2.0.2 170 3/13/2026
2.0.1 188 2/11/2026
2.0.0 489 11/18/2025
1.1.2 308 9/29/2025
1.1.1 274 9/8/2025
1.1.0 266 6/30/2025
1.0.0 252 6/30/2025