Switched to AutoMapper instance-based API

This commit is contained in:
Michael Grafnetter 2019-01-02 19:38:40 +01:00
parent 7747f96e45
commit 64ecf56dba
2 changed files with 9 additions and 8 deletions

View File

@ -1,6 +1,5 @@
namespace DSInternals.PowerShell.Commands
{
using System;
using System.Management.Automation;
using AutoMapper;
@ -11,10 +10,10 @@
protected override void BeginProcessing()
{
base.BeginProcessing();
Mapper.Initialize(cfg => cfg.CreateMap<DSInternals.DataStore.DomainController, DSInternals.PowerShell.DomainController>());
var dc = this.DirectoryContext.DomainController;
var dcTransfer = Mapper.Map<DSInternals.PowerShell.DomainController>(dc);
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<DSInternals.DataStore.DomainController, DSInternals.PowerShell.DomainController>()).CreateMapper();
var dcTransfer = mapper.Map<DSInternals.PowerShell.DomainController>(dc);
this.WriteObject(dcTransfer);
}
}
}
}

View File

@ -7,6 +7,8 @@
[OutputType(typeof(DSInternals.PowerShell.SchemaAttribute))]
public class GetADDBSchemaAttributeCommand : ADDBCommandBase
{
private IMapper mapper;
[Parameter(Position = 0, ValueFromPipeline = true)]
[Alias("LdapDisplayName,AttributeName,AttrName,Attr")]
[ValidateNotNullOrEmpty]
@ -19,7 +21,7 @@
protected override void BeginProcessing()
{
base.BeginProcessing();
Mapper.Initialize(cfg => cfg.CreateMap<DSInternals.DataStore.SchemaAttribute, DSInternals.PowerShell.SchemaAttribute>());
this.mapper = new MapperConfiguration(cfg => cfg.CreateMap<DSInternals.DataStore.SchemaAttribute, DSInternals.PowerShell.SchemaAttribute>()).CreateMapper();
}
protected override void ProcessRecord()
{
@ -29,7 +31,7 @@
var attributes = this.DirectoryContext.Schema.FindAllAttributes();
foreach (var attribute in attributes)
{
var attributeTransfer = Mapper.Map<DSInternals.PowerShell.SchemaAttribute>(attribute);
var attributeTransfer = this.mapper.Map<DSInternals.PowerShell.SchemaAttribute>(attribute);
this.WriteObject(attributeTransfer);
}
}
@ -39,10 +41,10 @@
foreach(string attributeName in this.Name)
{
var attribute = this.DirectoryContext.Schema.FindAttribute(attributeName);
var attributeTransfer = Mapper.Map<DSInternals.PowerShell.SchemaAttribute>(attribute);
var attributeTransfer = this.mapper.Map<DSInternals.PowerShell.SchemaAttribute>(attribute);
this.WriteObject(attributeTransfer);
}
}
}
}
}
}