View AddToCartPostHandler.cs
public class AddToCartPostHandler : IRequestPostProcessor<AddToCart, Unit>
{
private readonly ILogger<AddToCart> _logger;
public AddToCartPostHandler(ILogger<AddToCart> logger)
{
_logger = logger;
}
public Task Process(AddToCart request, Unit response)
{
View pipeline.cs
public class MyPipeline<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next)
{
return await next();
}
}
View Controller.cs
public class HomeController : Controller
{
private readonly IHomeHandler _handler;
public HomeController(IHomeHandler handler)
{
_handler = handler;
}
[HttpGet("/")]
View Controller.cs
public class HomeController : Controller
{
private readonly IMediator _mediator;
public HomeController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet("/")]
View Startup.cs
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new FeaturesViewLocator());
});
View FeaturesViewLocator.cs
public class FeaturesViewLocator : IViewLocationExpander
{
public void PopulateValues(ViewLocationExpanderContext context)
{
context.Values["customviewlocation"] = nameof(FeaturesViewLocator);
}
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
var viewLocationFormats = new[]
View HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using MusicStore.Models;
View bll.cs
public interface IProductManager
{
void AddProduct(Product product);
void UpdateProduct(int productId, Product product);
void DeleteProduct(int productId);
void IncreaseInventory(int productId, ProductInventory inventory);
void DecreaseInventory(int productId, ProductInventory inventory);
}
View repository.cs
public interface IProductRepository
{
void Insert(Product product);
void Delete(Product product);
IEnumerable<Product> GetById(Guid id);
IEnumerable<Product> GetAllActive();
IEnumerable<Product> FindByName(string name);
IEnumerable<Product> FindBySku(string name);
IEnumerable<Product> Find(string keyword, int limit, int page);
IEnumerable<Product> GetRelated(Guid id);
View addToCart.cs
public class AddToCartHandler : ICancellableAsyncRequestHandler<AddToCart, Unit>
{
private readonly IMediator _mediator;
private readonly MusicStoreContext _dbContext;
public AddToCartHandler(IMediator mediator, MusicStoreContext dbContext)
{
_mediator = mediator;
_dbContext = dbContext;
}