Outline

Solution: AutoMapper Dependency Injection

In the Conduit.Repositories Project we need to inject the Auto Mapper object into the Account Repository Class.

Modify Conduit.Repositories.AccountRepository.cs file
  • Add a private member
    • Type: IMapper
    • Name: Mapper
Modify the Constructor
  • Add parameter
    • Type: IMapper
    • Name: mapper
  • Assign the parameter value to the member

Take note of the upper- and lower-case character difference between the member and the parameter. In the next video I’ll show you my solution to injecting the Auto Mapper object.

Here's the abbreviated code for AccountRepository.cs file:

namespace Conduit.Repositories
{
    public class AccountRepository : IAccountRepository
    {
        private ConduitContext Context;
        private IMapper Mapper;
        private IConfiguration Configuration;
        private ILogger<AccountRepository> Logger;

        private async Task<Account> CreateAccountAsync(Register register)
        {
            // code removed for brevity
        }

        private void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt)
        {
            // code removed for brevity
        }

        private async Task<bool> UserExistAsync(Register register)
        {
            // code removed for brevity
        }

        public async Task<User> RegisterUserAsync(Register register)
        {
            // code removed for brevity
        }

        public AccountRepository(ConduitContext context, IMapper mapper, IConfiguration configuration, ILogger<AccountRepository> logger)
        {
            Context = context;
            Mapper = mapper;
            Configuration = configuration;
            Logger = logger;
        }
    }
}