Solution: Building Out the Repository Classes

In the Conduit.Repositories Project

Add IArticlesRepository Interface class without any method signatures

We're going to let Visual Studio do some work for us and create the method as we use them in the ArticlesController Class.

Here's the code for IArticlesRepository.cs file:

namespace Conduit.Repositories
    public interface IArticlesRepository
Add ArticlesRepository class and inject the following
  • IAccountRepository
  • IProfileRepository
  • ConduitContext
  • Imapper
  • Ilogger

Here's the code for the ArticlesRepository.cs file:

using AutoMapper;
using Conduit.Data;
using Microsoft.Extensions.Logging;

namespace Conduit.Repositories
    public class ArticlesRepository
        private IAccountRepository AccountRepo;
        private IProfileRepository ProfileRepo;
        private ConduitContext Context;
        private IMapper Mapper;
        private ILogger<ArticlesRepository> Logger;

        public ArticlesRepository(
            IAccountRepository accountRepo,
            IProfileRepository profileRepo,
            ConduitContext context,
            IMapper mapper,
            ILogger<ArticlesRepository> logger)
            AccountRepo = accountRepo;
            ProfileRepo = profileRepo;
            Context = context;
            Mapper = mapper;
            Logger = logger;

In the Conduit.Models Project

Add ArticleNotFoundException

In the Exceptions namespace

Here's the code for the ArticleNotFoundException.cs file:

using System;

namespace Conduit.Models.Exceptions
    public class ArticleNotFoundException : Exception
        public ArticleNotFoundException(string message) : base(message)


I finished! On to the next chapter