IocMapper.Microsoft.DependencyInjection 1.0.2

Suggested Alternatives

IocMapper

Additional Details

Merged into the base package - no longer needed.

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

IocMapper

Overview

The IocMapper is a tool to simplify mapping interfaces and implementations for dependency injection and IOC (Inversion of Control).

For instance, with Microsoft Dependency Injection, the following code is very common for IOC mappings:

builder.Services
    .AddTransient<IUserService, UserService>()
    .AddTransient<IAuthService, AuthService>()
    .AddTransient<IDataService, DataService>()
    .AddTransient<ISecurityService, TokenService>()
    .AddTransient<IEmailService, EmailService>()
    .AddTransient<IEncryptionService, EncryptionService>();

The IocMapper will make this easier by using a simple class attribute on each implementation class:

[Ioc]
public class UserService : IUserService { }

Then, all mappings can be automatically added with much simpler statement:

builder.Services.AddIocMappings();

Key Benefits

Attribute-driven IOC mappings will simplify day-to-day coding.

First, keep code that changes together close together:

  • Save time with mappings near the implementation, not some shared file in a completely separate part of project structure

Also, avoid constantly changing a central configuration file as new services are added:

  • Simplify change histories of a single, global configuration file
  • Avoid merge conflicts with multiple teams or developers constantly changing the same file

Lifetime Control

Natively define and control lifetimes of implementation objects directly in the mapping:

[Ioc(Lifetimes.Singleton)]
public class SecurityService : ISecurityService { }

Map Specific Implementations

Map to specific interfaces, even when classes inherit base classes or implement multiple interfaces:

[Ioc(Target = typeof(IUserService))]
public class UserService : ServiceBase, IUserProxy, IUserService { }

Also, map a class to itself to inject specific class without a specific interface implementation:

[Ioc(Lifetimes.Singleton, Target = typeof(Settings))]
public class Settings { }

Map Across Libraries

Add external libraries in addition to calling library with just a type from each library to include:

builder.Services.AddIocMappings(
    typeof(IExternalService),
    typeof(IOtherService));

Easily integrate dependencies across multiple libraries whether using onion/clean architecture, layered architecture, or just separate libraries.

A Note on Complexity

This tool is meant to make IOC mapping easier. It is not intended to cover all possible ways to register dependencies, otherwise it would just become the tool it is trying to simplify and become too complex itself.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.2 389 4/12/2023 1.0.2 is deprecated because it is no longer maintained.
1.0.1 296 6/2/2022

Updating framework versions