AdaskoTheBeAsT.AutoMapper.SimpleInjector alternatives and similar packages
Based on the "IoC" category.
Alternatively, view AdaskoTheBeAsT.AutoMapper.SimpleInjector alternatives based on common mentions on social networks and blogs.
-
Castle Windsor
Castle Windsor is a best of breed, mature Inversion of Control container available for .NET -
Microsoft.Extensions.DependencyInjection
DISCONTINUED. The default IoC container for ASP.NET Core applications. -
Simple Injector
An easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success. -
TinyIoC
An easy to use, hassle free, Inversion of Control Container for small projects, libraries and beginners alike. -
DryIoc is fast, small, full-featured IoC Container for .NET
DryIoc is fast, small, full-featured IoC Container for .NET -
Simplify.DI
Simplify is an open-source set of lightweight .NET libraries that provide infrastructure for your applications. DI and mocking friendly.
CodeRabbit: AI Code Reviews for Developers

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of AdaskoTheBeAsT.AutoMapper.SimpleInjector or a related project?
README
AdaskoTheBeAsT.AutoMapper.SimpleInjector
AutoMapper extensions for SimpleInjector
Badges
Usage
Scans assemblies and:
- adds profiles to mapping configuration
- adds implementations of
ITypeConverter
,IValueConverter
,IValueResolver
,IMemberValueResolver
,IMappingAction
instances as transient to the container.
There are few options to use with Container
instance:
- Marker type from assembly which will be scanned
container.AddAutoMapper(typeof(MyMapper), type2 /*, ...*/);
- List of assemblies which will be scanned.
Below is sample for scanning assemblies from some solution.
```cs
[ExcludeFromCodeCoverage]
public static class AutoMapperConfigurator
{
private const string NamespacePrefix = "YourNamespace";
public static void Configure(Container container)
{
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
var assemblies = new List<Assembly>();
var mainAssembly = typeof(AutoMapperConfigurator).Assembly;
var refAssemblies = mainAssembly.GetReferencedAssemblies();
foreach (var assemblyName in refAssemblies
.Where(a => a.FullName.StartsWith(NamespacePrefix, StringComparison.OrdinalIgnoreCase)))
{
var assembly = loadedAssemblies.Find(l => l.FullName == assemblyName.FullName)
?? AppDomain.CurrentDomain.Load(assemblyName);
assemblies.Add(assembly);
}
container.AddAutoMapper(assemblies);
}
}
This registers AutoMapper:
- `MapperConfiguration` - As a singleton
- `IMapper` - As a singleton
- `ITypeConverter` instances as transient
- `IValueConverter` instances as transient
- `IValueResolver` instances as transient
- `IMemberValueResolver` instances as transient
- `IMappingAction` instances as transient
Mapping configuration is static as it is the root object that can create an `IMapper`.
Mapper instance are registered as singleton. You can configure this with the `Lifestyle` parameter. Be careful changing this, as `Mapper` takes a dependency on a factory method to instantiate the other extensions.
## Advanced usage
### Setting up custom `IMapper` instance and marker type from assembly for unit testing (Moq sample)
```cs
var testMapper = new Mock<IMapper>();
container.AddAutoMapper(
cfg =>
{
cfg.Using(() => testMapper.Object);
cfg.WithMapperAssemblyMarkerTypes(typeof(MyMarkerType));
});
Setting up custom IMapper
implementation and marker type from assembly
container.AddAutoMapper(
cfg =>
{
cfg.Using<MyCustomMapper>();
cfg.WithMapperAssemblyMarkerTypes(typeof(MyMarkerType));
});
Setting up custom IMapper
implementation and assemblies to scan
container.AddAutoMapper(
cfg =>
{
cfg.Using<MyCustomMapper>();
cfg.WithAssembliesToScan(assemblies);
});
Setting assemblies to scan and different lifetime for IMapper
implementation
container.AddAutoMapper(
cfg =>
{
cfg.WithAssembliesToScan(assemblies);
cfg.AsScoped();
});
Setting configuration for MapperConfigurationExpression
container.AddAutoMapper(
cfg =>
{
cfg.WithAssembliesToScan(assemblies);
cfg.AsScoped();
cfg.WithMapperConfigurationExpressionAction(
(
container1,
expression) => expression.CreateMap<Foo, Bar>().ReverseMap());
});
Library scans all descendant classes from Profile
so it is better to store mapping in Profile
descendants
public class Profile1 : Profile
{
public Profile1()
{
CreateMap<Source, Dest>();
}
}
Mapper.Map usage
To map at runtime, add a dependency on IMapper
:
public class EmployeesController {
private readonly IMapper _mapper;
public EmployeesController(IMapper mapper)
=> _mapper = mapper;
// use _mapper.Map to map
}
ProjectTo usage
Starting with 8.0 you can use IMapper.ProjectTo
. The old ProjectTo
is an extension method and does not have dependency injection available. Pass an IConfigurationProvider
instance directly:
var orders = await dbContext.Orders
.ProjectTo<OrderDto>(_configurationProvider)
.ToListAsync();
Or you can use an IMapper
instance:
var orders = await dbContext.Orders
.ProjectTo<OrderDto>(_mapper.ConfigurationProvider)
.ToListAsync();
Thanks to:
- Jimmy Boggard for AutoMapper
- Steven van Deursen for SimpleInjector
Code originates from AutoMapper.Extensions.Microsoft.DependencyInjection and was changed to work with SimpleInjector.