title: Decorate BaseController with Scrutor in .netCore 3.1
body: <p>I have an application in .net core 3.1 with angular front end. I want to use the decorator to the base controller in order to log CUD operations in the entire application. I am using Scrutor nuget package in the project.</p>
  <p>The Base Controller is the following</p>
  <pre><code>    using System.Collections.Generic;
  using System.Threading.Tasks;
  using AutoMapper;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Logging;
  using Xenagos.Data;
  using Xenagos.Data.EFCore;
  using Xenagos.ViewModels;
  
  namespace Xenagos.Controllers
  {
      [Route(&quot;api/[controller]&quot;)]
      [ApiController]
      public abstract class BaseController&lt;TEntity, TViewEntity, TRepository&gt; : ControllerBase, IBaseController&lt;TEntity, TViewEntity&gt; 
          where TEntity : class
          where TViewEntity : class, IViewEntity
          where TRepository : IRepository&lt;TEntity&gt;
      {
          private readonly IRepository&lt;TEntity&gt; repository;
          private readonly IMapper mapper;
  
          public BaseController(TRepository repository, IMapper mapper)
          {
              this.repository = repository;
              this.mapper = mapper;
          }
  
  
          // GET: api/[controller]
          [HttpGet]
          public virtual async Task&lt;ActionResult&lt;ComplexData&lt;TViewEntity&gt;&gt;&gt; Get()
          {
              var results = await repository.GetAll();
              List&lt;TViewEntity&gt; resultsView =
                  this.mapper.Map&lt;List&lt;TEntity&gt;, List&lt;TViewEntity&gt;&gt;(results);
              return Ok(new ComplexData&lt;TViewEntity&gt;(resultsView));
          }
  
          // GET: api/[controller]/5
          [HttpGet(&quot;{id}&quot;)]
          public async Task&lt;ActionResult&lt;TEntity&gt;&gt; Get(int id)
          {
              var entity = await repository.Get(id);
              if (entity == null)
              {
                  return NotFound();
              }
  
              return entity;
          }
  
          // PUT: api/[controller]/5
          [HttpPut(&quot;{id}&quot;)]
          public virtual async Task&lt;IActionResult&gt; Put(string id, TViewEntity entity)
          {
              if (!id.Equals(entity.Id))
              {
                  return BadRequest();
              }
              await repository.Update(this.mapper.Map&lt;TEntity&gt;(entity));
              return NoContent();
          }
  
          // POST: api/[controller]
          [HttpPost]
          public virtual async Task&lt;ActionResult&lt;TEntity&gt;&gt; Post(TViewEntity entity)
          {
              await repository.Add(this.mapper.Map&lt;TEntity&gt;(entity));
              return CreatedAtAction(&quot;Get&quot;, new { id = entity.Id }, entity);
          }
  
          // DELETE: api/[controller]/5
          [HttpDelete(&quot;{id}&quot;)]
          public async Task&lt;ActionResult&lt;TViewEntity&gt;&gt; Delete(int id)
          {
              var entity = await repository.Delete(id);
              if (entity == null)
              {
                  return NotFound();
              }
              return this.mapper.Map&lt;TViewEntity&gt;(entity);
          }
      }
  }
  </code></pre>
  <p>The decorator I made is the following</p>
  <pre><code>using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Logging;
  using Newtonsoft.Json;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Xenagos.Controllers;
  using Xenagos.ViewModels;
  
  namespace Xenagos.Data
  {
      public class LoggingDecorator&lt;T, TViewEntity, TRepository&gt; : IBaseController&lt;T, TViewEntity&gt;
          where T : class
          where TViewEntity : class, IViewEntity
          where TRepository : IRepository&lt;T&gt;
      {
  
          private IBaseController&lt;T, TViewEntity&gt; _baseController;
          private readonly ILogger&lt;LoggingDecorator&lt;T, TViewEntity, TRepository&gt;&gt; _logger;
  
          public LoggingDecorator(IBaseController&lt;T, TViewEntity&gt; baseController, ILogger&lt;LoggingDecorator&lt;T, TViewEntity, TRepository&gt;&gt; logger)
          {
              _baseController = baseController;
              _logger = logger;
          }
  
          Task&lt;ActionResult&lt;TViewEntity&gt;&gt; IBaseController&lt;T, TViewEntity&gt;.Delete(int id)
          {
              _logger.LogWarning($&quot;Deleting record from ... with ID:{id}&quot;);
              Task&lt;ActionResult&lt;TViewEntity&gt;&gt; result = _baseController.Delete(id);
  
              return result;
          }
  
          public Task&lt;ActionResult&lt;ComplexData&lt;TViewEntity&gt;&gt;&gt; Get()
          {
              return _baseController.Get();
          }
  
          Task&lt;ActionResult&lt;T&gt;&gt; IBaseController&lt;T, TViewEntity&gt;.Get(int id)
          {
              return _baseController.Get(id);
          }
  
          public Task&lt;ActionResult&lt;T&gt;&gt; Post(TViewEntity entity)
          {
              _logger.LogWarning($&quot;Adding new record from ... with object data :{JsonConvert.SerializeObject(entity)}&quot;);
              return _baseController.Post(entity);
          }
  
          public Task&lt;IActionResult&gt; Put(string id, TViewEntity entity)
          {
              _logger.LogWarning($&quot;updating record from ... with object data :{JsonConvert.SerializeObject(entity)}&quot;);
              Task&lt;IActionResult&gt; result = _baseController.Put(id, entity);
  
              return result;
          }
      }
  }
  </code></pre>
  <p>In the startup class in the <code>public void ConfigureServices(IServiceCollection)</code> I use the following lines</p>
  <pre><code>services.AddScoped&lt;IBaseController&lt;Models.Property, PropertyViewModel&gt;, BaseController&lt;Models.Property, PropertyViewModel, PropertyRepository&gt;&gt;();
              services.Decorate&lt;IBaseController&lt;Models.Property, PropertyViewModel&gt;, LoggingDecorator&lt;Models.Property, PropertyViewModel, PropertyRepository&gt;&gt;();
  </code></pre>
  <p>I have extracted an Interface from the base controller, on top of all the previous actions.
  While the application runs, it does not call/pass-through the decorator. What I'm missing here ?
  I haven't used the decorator pattern with .net core and dependency injection before. All the added code is in the backend only, I haven't altered the front end at all.</p>
  <p>Thank you in advance.</p>