Dreamine.MVVM.Locators 1.0.10

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

Dreamine.MVVM.Locators

View ↔ ViewModel mapping infrastructure for the Dreamine MVVM framework.

This library provides a lightweight ViewModel locator that supports convention-based resolution, manual registration, reverse view resolution, and Dependency Injection integration.

It is designed as a platform-agnostic mapping engine. It focuses on finding the correct ViewModel type from a View type, or the correct View type from a ViewModel type, using naming and namespace conventions.

WPF-specific concerns such as DataContext, FrameworkElement, and Loaded event wiring should be handled outside this library.

➡️ 한국어 문서 보기

Features

  • Convention-based View ↔ ViewModel mapping
  • Manual ViewModel registration
  • Optional DI resolver integration
  • Automatic assembly scanning
  • Reverse View resolution from ViewModel
  • Reset and cache clearing APIs for tests and application reconfiguration
  • Root namespace lookup support
  • Nested namespace and subfolder lookup support
  • Flexible namespace candidate expansion for structures such as:
    • Views
    • View
    • Pages
    • Windows
    • Dialogs
    • GUI
    • GUIs
    • Screens
    • Controls

Design Goal

Dreamine.MVVM.Locators is not intended to be tied directly to WPF-only types.

Its responsibility is:

  • resolve ViewModel types from View types
  • resolve View types from ViewModel types
  • provide a consistent convention engine
  • support manual overrides and DI-based creation

Its responsibility is not:

  • setting DataContext
  • subscribing to Loaded events
  • checking Window, Page, or UserControl inheritance

Those platform-specific behaviors should be implemented in a separate WPF-focused layer.

Mapping Behavior

The locator resolves types in the following order.

View → ViewModel

  1. Manual registration map
  2. Convention-based namespace candidates
  3. Parent namespace expansion
  4. Root namespace lookup
  5. Assembly-wide fallback by type name

Example candidates for a View named MainWindow:

  • MyApp.ViewModels.MainWindowViewModel
  • MyApp.Views.Admin.MainWindowMyApp.ViewModels.Admin.MainWindowViewModel
  • MyApp.GUI.Login.MainWindowMyApp.ViewModels.Login.MainWindowViewModel
  • MyApp.MainWindowViewModel

ViewModel → View

  1. Convention-based namespace candidates
  2. Parent namespace expansion
  3. Root namespace lookup
  4. Assembly-wide fallback by type name

Supported Structure Examples

Root namespace

namespace MyApp;

public partial class MainWindow
{
}

public sealed class MainWindowViewModel
{
}

Standard Views / ViewModels structure

namespace MyApp.Views;

public partial class MainWindow
{
}

namespace MyApp.ViewModels;

public sealed class MainWindowViewModel
{
}

Nested folders

namespace MyApp.Views.Admin;

public partial class MainWindow
{
}

namespace MyApp.ViewModels.Admin;

public sealed class MainWindowViewModel
{
}

Alternative folder names

namespace MyApp.GUI.Account;

public partial class LoginDialog
{
}

namespace MyApp.ViewModels.Account;

public sealed class LoginDialogViewModel
{
}

Dependency Injection Support

ViewModel instances are created through a registered resolver.

resolver.Resolve(vmType)

There is no Activator.CreateInstance fallback for ViewModel creation. If no resolver is registered, or if the resolver returns null, Resolve(...) throws an InvalidOperationException with a message that distinguishes those two cases.

Usage

Register Resolver

ViewModelLocator.RegisterResolver(new MyResolver());

Clear Locator State

ViewModelLocator.Clear();         // clears mappings and lookup caches, keeps resolver
ViewModelLocator.ClearResolver(); // removes the resolver only
ViewModelLocator.Reset();         // clears mappings, lookup caches, and resolver

Reset() is useful for unit-test isolation. Clear() is useful when mappings should be rebuilt while keeping the same DI strategy.

Manual Mapping

ViewModelLocator.Register(typeof(MainWindow), typeof(MainWindowViewModel));

Resolve ViewModel

var vm = ViewModelLocator.Resolve(typeof(MainWindow));

Resolve View

var view = ViewModelLocator.ResolveView(typeof(MainWindowViewModel));

Auto Register

ViewModelLocator.RegisterAll(Assembly.GetExecutingAssembly());

The locator supports broad matching, but the recommended structure is still:

  • Views
  • ViewModels

This keeps projects predictable and reduces ambiguity when multiple candidates share the same type name.

Notes

  • Broad matching improves flexibility, but duplicate type names can cause ambiguous fallback resolution.
  • When multiple candidates may exist, prefer manual registration.
  • Use this library for mapping and creation, not for platform event wiring.
  • AppDomain type scans are cached and invalidated when a new assembly is loaded or when Clear() / Reset() is called.

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.  net10.0 was computed.  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 (5)

Showing the top 5 NuGet packages that depend on Dreamine.MVVM.Locators:

Package Downloads
Dreamine.MVVM.Core

Core runtime package for Dreamine MVVM, including base ViewModel types, notification support, and foundational services.

Dreamine.MVVM.Locators.Wpf

WPF-specific locator components for automatic View-to-ViewModel wiring and dependency injection in Dreamine MVVM.

Dreamine.MVVM.FullKit

All-in-one package for Dreamine MVVM on WPF. Includes core MVVM modules and automatic source generator integration.

Dreamine.MVVM.Wpf

WPF-specific bootstrap and runtime integration layer for the Dreamine MVVM framework.

Dreamine.UI.Wpf.Controls

Custom WPF controls for the Dreamine UI library: DreamineButton, DreamineTextBox, MessageBox, Navigation, and more.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.10 231 7/8/2026
1.0.9 229 5/9/2026
1.0.8 147 4/30/2026
1.0.7 171 3/22/2026
1.0.6 112 3/21/2026
1.0.5 149 3/21/2026
1.0.4 215 5/31/2025
1.0.3 239 5/29/2025
1.0.2 232 5/26/2025
1.0.1 239 5/25/2025
1.0.0 251 5/25/2025