Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.21 KB

File metadata and controls

50 lines (40 loc) · 1.21 KB

FluentUtils.AutoMapper.Extensions.Microsoft.DependencyInjection

Example Usage

Use AddAutoMapperProfiles and pass it a params array of assemblies which contain classes implementing the IMapFrom<> and IReverseMapFrom<> interfaces.

// Program.cs
var builder = WebApplication.CreateBuilder(args);

// Register automapper profiles in the assembly containing the Program class
builder.Services.AddAutoMapperProfiles(typeof(Program).Assembly);

IMapFrom<>

public class User
{
    public Guid Id { get; set; }
    public string FullName { get; set; }
    public DateTime Created { get; set; }
}

// This will allow automapper to map Users to UserDtos
public class UserDto : IMapFrom<User>
{
    public Guid Id { get; set; }
    public string FullName { get; set; }
}

IReverseMapFrom<>

public class User
{
    public Guid Id { get; set; }
    public string FullName { get; set; }
    public DateTime Created { get; set; }
}

// This will allow automapper to map Users to UserDtos and then back to Users
public class UserDto : IReverseMapFrom<User>
{
    public Guid Id { get; set; }
    public string FullName { get; set; }
}