Solution: Modify ProfilesController

In the Conduit.Api Project

Modify the ProfilesController by adding the following method
  • Name: GetProfileAsync
  • Return Type: IActionResult
  • Parameters: [FromRoute] string userName
Add the following Attributes to the method:


Finally, inject the following:


Here's the code for the method GetProfileAsync in the ProfilesController.cs file:

using Conduit.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;

namespace Conduit.Api.Controllers
    public class ProfilesController : ControllerBase
        private IProfileRepository ProfileRepo;
        private ILogger<ProfilesController> Logger;

        public async Task<IActionResult> GetProfileAsync([FromRoute]string userName)


        public ProfilesController(IProfileRepository profileRepo, ILogger<ProfilesController> logger)
            ProfileRepo = profileRepo;
            Logger = logger;
Modify the Startup.cs file

Configure IProfileRepository for Dependency Injection

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

using ...

namespace Conduit.Api
    public class Startup
        public Startup(IConfiguration configuration)...

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
            var key = Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:Token").Value);
                .AddJwtBearer(options =>...);
            services.AddDbContext<ConduitContext>(options =>...);
            services.AddAutoMapper(cfg =>...);
            services.AddScoped<IAccountRepository, AccountRepository>();
            services.AddScoped<IProfileRepository, ProfileRepository>(); // <-- Dependency Injection Configuration
            services.Configure<ApiBehaviorOptions>(options =>...);
            services.AddSwaggerGen(c =>...);

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)...

I finished! On to the next chapter