XInject.MVVM 1.2.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package XInject.MVVM --version 1.2.1
NuGet\Install-Package XInject.MVVM -Version 1.2.1
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="XInject.MVVM" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XInject.MVVM --version 1.2.1
#r "nuget: XInject.MVVM, 1.2.1"
#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.
// Install XInject.MVVM as a Cake Addin
#addin nuget:?package=XInject.MVVM&version=1.2.1

// Install XInject.MVVM as a Cake Tool
#tool nuget:?package=XInject.MVVM&version=1.2.1

XInject Banner

XInject

Automatic service registration extensions for Microsoft.Extensions.DependencyInjection.

License

🚀 Getting Started

The packages may be installed via Nuget, the Package Manager Console, or the DotNet CLI.

Nuget

Package Manager Console

Install-Package XInject
Install-Package XInject.MVVM

DotNet CLI

dotnet add package XInject
dotnet add package XInject.MVVM

📂 What's Included

Projects

Name Description Framework
XInject Contains configurable automatic service registration extension methods for the IServiceCollection. any
XInject.MVVM Contains automatic view and viewmodel registration extension methods for the IServiceCollection in WPF projects using the MVVM architecture. >= net6.0-windows

Types

Name Description
SingletonAttribute Specifies that a view or service should be registered with a ServiceLifetime of ServiceLifetime.Singleton.
TransientAttribute Specifies that a view or service should be registered with a ServiceLifetime of ServiceLifetime.Transient.
ScopedAttribute Specifies that a service should be registered with a ServiceLifetime of ServiceLifetime.Scoped.
ServiceRegistrationStrategy Specifies strategies that may be applied when adding a ServiceDescriptor to an IServiceCollection.

Extension Methods (for IServiceCollection)

Method Description
RegisterApplicationServices(optional: ServiceRegistrationStrategy) Registers service objects that have been defined within the application's assembly.
RegisterAssemblyServices(Assembly, optional: ServiceRegistrationStrategy) Registers service objects that have been defined within the specified assembly.
RegisterViewsAndViewModels() Registers view and viewmodel objects that have been defined within the application's assembly.

🪄 Example Usage

Console App (XInject)

// in ConsoleApp/Program.cs

var services = new ServiceCollection()
  .RegisterApplicationServices() // from ConsoleApp.Services
  .BuildServiceProvider();

var service = services.GetRequiredService<IExampleService>();

service.DoWork();

// in ConsoleApp/Services/IExampleService.cs

public interface IExampleService()
{
  void DoWork();
}
// in ConsoleApp/Services/ExampleService.cs
// Compiled descriptor will be (IExampleService, ExampleService, ServiceLifetime.Transient)

[Transient]
public class ExampleService : IExampleService
{
  public void DoWork()
  {
    Console.WriteLine("Hello World");
  }
}

WPF APP with MVVM Architecture (XInject.MVVM)

// in WPFApp/App.xaml.cs

protected override void OnStartup(StartupEventArgs e)
{
  var services = new ServiceCollection()
    .RegisterApplicationServices()  // from WPFApp.Services
    .RegisterViewsAndViewModels() // from WPFApp.Views && WPFApp.ViewModels
    .BuildServiceProvider();
    
  var mainWindow = services.GetRequiredService<MainWindow>();
  
  mainWindow.Show();
  
  base.OnStartup(e);
}
// in WPFApp/Views/MainWindow.cs

public partial class MainWindow : Window
{
  ...
}
// in WPFApp/Views/CustomDialogWindow.cs
// Override the default lifetime of the view

[Transient] 
public partial class CustomDialogWindow : Window
{
  ...
}
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-windows7.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated