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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
InjectX ยท
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 | Versions 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
- Ch0pstix.InjectX.Shared (>= 1.0.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 |
---|---|---|
1.0.0 | 484 | 2/11/2023 |