Ch0pstix.InjectX.Mvvm 1.0.0

dotnet add package Ch0pstix.InjectX.Mvvm --version 1.0.0
NuGet\Install-Package Ch0pstix.InjectX.Mvvm -Version 1.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="Ch0pstix.InjectX.Mvvm" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ch0pstix.InjectX.Mvvm --version 1.0.0
#r "nuget: Ch0pstix.InjectX.Mvvm, 1.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.
// Install Ch0pstix.InjectX.Mvvm as a Cake Addin
#addin nuget:?package=Ch0pstix.InjectX.Mvvm&version=1.0.0

// Install Ch0pstix.InjectX.Mvvm as a Cake Tool
#tool nuget:?package=Ch0pstix.InjectX.Mvvm&version=1.0.0

InjectX ยท License

InjectX Banner

Automatic service registration extensions for Microsoft.Extensions.DependencyInjection.

๐Ÿš€ Getting Started

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

Nuget

Package Manager Console

Install-Package InjectX
Install-Package InjectX.Mvvm

DotNet CLI

dotnet add package InjectX
dotnet add package InjectX.Mvvm

๐Ÿ“‚ What's Included

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.
RegistrationStrategy Specifies strategies that may be applied when adding a ServiceDescriptor to an IServiceCollection.

Extension Methods

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

๐Ÿ’ก Usage Examples

Console App (InjectX)

MyConsoleApp/Program.cs
using MyConsoleApp.Services;

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

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

service.SayHello();
MyConsoleApp/Services/IExampleService.cs
public interface IExampleService()
{
  void SayHello();
}
MyConsoleApp/Services/ExampleService.cs
[Transient] // Compiled descriptor will be (IExampleService, ExampleService, ServiceLifetime.Transient)
public class ExampleService : IExampleService
{
  public void SayHello()
  {
    Console.WriteLine("Hello World");
  }
}

Wpf Mvvm App (InjectX + InjectX.Mvvm)

MyWpfApp/App.xaml.cs:
public partial class App : Application
{
  protected override void OnStartup(StartupEventArgs e)
  {
    var services = new ServiceCollection()
      .RegisterApplicationServices()  // from MyWpfApp.Services*
      .RegisterViewsAndViewModels() // from MyWpfApp.Views* && MyWpfApp.ViewModels*
      .BuildServiceProvider();
      
    var mainWindow = services.GetRequiredService<MainWindow>();
    
    mainWindow.Show();
    
    base.OnStartup(e);
  }
}
MyWpfApp/Views/Dialogs/MyCustomDialogWindow.cs:
[Transient] // Override the default singleton lifetime as dialogs tend to be reusable objects
public partial class MyCustomDialogWindow : Window
{
  public MyCustomDialogWindow()
  {
    InitializeComponent();
  }
}
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.

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
1.0.0 452 2/11/2023