Go To Application Folder (Layer) And Create Command Or Query and Use down Code in Application Layer .
You Should Use "ICommand" for Command
Use "IQuery" for Query Requests , like this :
Sample Command And CommandHandler
// Use ICommand In Command ModelpublicclassCreateProductCommand:ICommand{publicstringProductName{get;set;}}
#region Handle
// Use ICommandHandler In Command HandlerpublicasyncValueTask<Unit>Handle(CreateProductCommandrequest,CancellationTokencancellationToken){varcreateProduct= GenereateCreateProductDtoFromaCommand(request);await _productRepository.CreateProduct(createProduct,cancellationToken).ConfigureAwait(false);return Unit.Value;}
#endregion
#region Private
private Product GenereateCreateProductFromaCommand(CreateProductCommandcommand)=>new Product(command.ProductName);
#endregion Private
Sample Query And QueryHandler
// Use IQuery In Query Model publicclassGetProductQuery:IQuery<IEnumerable<ProductVM>>{publicintProductId{get;set;}}
#region Handle
// Use IQueryHandler In Query HandlerpublicasyncValueTask<IEnumerable<ProductVM>>Handle(GetProductQueryrequest,CancellationTokencancellationToken){varproducts=await _productService.GetProduct(cancellationToken).ConfigureAwait(false);varproductVMs= CreateProductVM(products);returnproductVMs;}
#endregion
#region Private
privateIEnumerable<ProductVM>CreateProductVM(IEnumerable<Product>products){ICollection<ProductVM>productVMs=newList<ProductVM>();foreach(var product in products)
productVMs.Add(new ProductVM(){Id= product.Id,Name= product.Name,});returnproductVMs;}
#endregion Private
About
Separating commands and queries in User Mediator In .Net 6