Skip to content

Instantly share code, notes, and snippets.

@tatarincev
Created January 14, 2021 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatarincev/5f9f7efe797a389f084b4cfbcb515a64 to your computer and use it in GitHub Desktop.
Save tatarincev/5f9f7efe797a389f084b4cfbcb515a64 to your computer and use it in GitHub Desktop.
public class Module : IModule
{
public void Initialize(IServiceCollection serviceCollection)
{
//register CustomerOrderService in DI first
serviceCollection.AddTransient<CustomerOrderService>();
//Register decorator for original CustomerOrderService
serviceCollection.AddTransient<ICustomerOrderService>(provider => new MyCoolCustomerOrderService(provider.GetRequiredService<CustomerOrderService>()));
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Services;
namespace VirtoCommerce.OrdersModule.Data.Services
{
public class MyCoolCustomerOrderService : ICustomerOrderService
{
private readonly ICustomerOrderService _originalService;
public MyCoolCustomerOrderService(ICustomerOrderService originalService)
{
_originalService = originalService;
}
public Task DeleteAsync(string[] ids)
{
return _originalService.DeleteAsync(ids);
}
public Task<CustomerOrder> GetByIdAsync(string orderId, string responseGroup = null)
{
return _originalService.GetByIdAsync(orderId, responseGroup);
}
public Task<CustomerOrder[]> GetByIdsAsync(string[] orderIds, string responseGroup = null)
{
return _originalService.GetByIdsAsync(orderIds, responseGroup);
}
public Task SaveChangesAsync(CustomerOrder[] orders)
{
//TODO: Add validation logic here
return _originalService.SaveChangesAsync(orders);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment