Skip to content

CodeMaru-Dreamine/Dreamine.MVVM.Core

Repository files navigation

Dreamine.MVVM.Core

Dreamine.MVVM.Core is the lightweight runtime infrastructure module of the Dreamine MVVM framework.

It provides the default dependency injection implementation used by Dreamine modules, including explicit service registration, constructor-based resolution, singleton instance handling, object activation, and convention-based auto-registration.

This package is intentionally focused on runtime infrastructure. It must remain independent from WPF-specific UI concepts such as Window, UserControl, FrameworkElement, ContentControl, and DataContext.

➡️ 한국어 문서 보기


What this library provides

Dreamine.MVVM.Core provides:

  • DMContainer static facade
  • DreamineContainer default dependency container implementation
  • transient service registration
  • singleton service registration
  • factory-based service registration
  • constructor-based dependency resolution
  • singleton instance caching
  • circular dependency detection
  • convention-based auto-registration
  • assembly type scanning
  • object activation through IObjectActivator

Package Role

Dreamine.MVVM.Core implements infrastructure contracts defined by Dreamine.MVVM.Interfaces.

Recommended dependency direction:

Dreamine.MVVM.Interfaces
        ↑
Dreamine.MVVM.Core
        ↑
Dreamine.MVVM.Wpf / Dreamine.MVVM.Locators / Application modules

Dreamine.MVVM.Core should not contain WPF-specific binding or navigation logic. WPF-specific behavior belongs in WPF-focused packages.


Service Lifetime Policy

Dreamine.MVVM.Core uses explicit lifetime behavior.

Registration API Lifetime Notes
Register<TImplementation>() Transient Creates a new instance when resolved.
Register<TService, TImplementation>() Transient Uses abstraction-to-implementation mapping.
Register<TService>(Func<TService>) Transient Executes the factory whenever resolved.
RegisterSingleton<TService>(TService) Singleton Stores the provided instance.
RegisterSingleton<TImplementation>() Singleton Creates and caches one instance on first resolve.
RegisterSingleton<TService, TImplementation>() Singleton Abstraction-to-implementation singleton mapping.
AutoRegisterAll(Assembly) Singleton for matched types Preserves Dreamine auto-registration behavior.

Important: auto-registered types are registered as singleton services by default. This keeps automatically discovered ViewModels, Models, Events, and Managers stable across repeated resolution unless the application explicitly registers another lifetime.


Auto-Registration

DMContainer.AutoRegisterAll(rootAssembly) scans candidate assemblies and registers supported concrete types.

Auto-registration is implemented through:

  • AutoRegistrationService
  • AssemblyTypeScanner
  • NamingConventionAutoRegistrationFilter

The current naming convention targets concrete non-generic classes whose names or full names match supported Dreamine conventions, including:

  • *Model
  • *Event
  • *Manager
  • *ViewModel
  • .xaml.Model
  • .xaml.Event
  • .xaml.ViewModel

Matched types are registered using singleton lifetime.


Project Structure

Dreamine.MVVM.Core
├── DMContainer.cs
├── AutoRegistration
│   ├── AssemblyTypeScanner.cs
│   ├── AutoRegistrationService.cs
│   └── NamingConventionAutoRegistrationFilter.cs
└── DependencyInjection
    ├── ConstructorActivator.cs
    ├── ConstructorSelector.cs
    ├── DreamineContainer.cs
    ├── ResolutionContext.cs
    ├── ServiceDescriptor.cs
    ├── ServiceLifetime.cs
    └── ServiceRegistry.cs

Requirements

  • .NET: net8.0

Installation

Project Reference

<ItemGroup>
  <ProjectReference Include="..\Dreamine.MVVM.Interfaces\Dreamine.MVVM.Interfaces.csproj" />
  <ProjectReference Include="..\Dreamine.MVVM.Core\Dreamine.MVVM.Core.csproj" />
</ItemGroup>

NuGet

dotnet add package Dreamine.MVVM.Core

Quick Start

Register a transient service

DMContainer.Register<IMyService, MyService>();

Register a factory

DMContainer.Register<IMyService>(() => new MyService());

Register a singleton instance

var service = new MyService();
DMContainer.RegisterSingleton<IMyService>(service);

Register a singleton type

DMContainer.RegisterSingleton<IMyService, MyService>();

Resolve a service

IMyService service = DMContainer.Resolve<IMyService>();

Auto-register Dreamine application types

DMContainer.AutoRegisterAll(typeof(App).Assembly);

Component Reference

DMContainer

DMContainer is a static facade over the default DreamineContainer instance.

Its role is to preserve simple application-level usage while delegating actual behavior to focused infrastructure components.

DMContainer should remain thin. It should not directly contain assembly scanning, constructor selection, object activation, or lifetime-management logic.


DreamineContainer

DreamineContainer is the default dependency container implementation.

Responsibilities:

  • store service descriptors
  • resolve registered services
  • resolve constructor dependencies
  • cache singleton instances
  • create transient instances
  • detect circular dependencies during resolution
  • delegate object creation to IObjectActivator

ConstructorActivator

ConstructorActivator creates object instances using constructor injection.

Responsibilities:

  • select a constructor through IConstructorSelector
  • resolve constructor parameters through IServiceResolver
  • create an object instance through reflection

AutoRegistrationService

AutoRegistrationService performs convention-based service registration.

Responsibilities:

  • scan candidate assemblies
  • filter supported concrete types
  • register matched types as singleton services

Design Goals

Dreamine.MVVM.Core prioritizes:

  • explicit behavior over hidden runtime magic
  • low dependency surface
  • constructor-based composition
  • interface-driven infrastructure
  • predictable service lifetime behavior
  • compatibility with Dreamine auto-registration
  • separation between contracts and implementations
  • independence from WPF-specific UI concerns

Related Modules

Typical composition with other Dreamine packages:

  • Dreamine.MVVM.Interfaces
  • Dreamine.MVVM.Attributes
  • Dreamine.MVVM.Generators
  • Dreamine.MVVM.Locators
  • Dreamine.MVVM.Locators.Wpf
  • Dreamine.MVVM.ViewModels
  • Dreamine.MVVM.Wpf

License

MIT License

About

Lightweight MVVM infrastructure for modern .NET desktop applications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages