How to Overwrite GetCartQuery graphql response?

I want to overwrite GetCartQuery response and some validation on data. For that, I am trying to overwrite CartAggregateRepository. I am using the following code to extend this class:

        serviceCollection.AddTransient<ICartAggregateRepository, CartAggregateRepositoryExtended>();


public class CartAggregateRepositoryExtended : CartAggregateRepository

However, it still goes CartAggregateRepository for processing. I want to modify a price validation rule which overwrites the extended price.

Can someone please guide with example?


Hi @bhushan-oe

I recommend to look on sample module vc-module-experience-api/samples/VirtoCommerce.Exp.ExtensionSamples/Module.cs

Here are some suggestions to help resolve your issue:

  1. Dependency Declaration in module.manifest: Ensure that you’ve correctly declared the dependency on VirtoCommerce.ExperienceApi in your module.manifest file. Here’s an example of how it should be done:


    <dependency id="VirtoCommerce.ExperienceApi" version="3.800.0" />
  1. Placement of AddTransient: The AddTransient registration should be placed inside the Initialize(IServiceCollection services) method of your module. This ensures that your extended repository is properly registered with the dependency injection container. Here’s how you should include it:
public class YourModule : Module
    public override void Initialize(IServiceCollection services)
        // Other registrations...
        services.AddTransient<ICartAggregateRepository, CartAggregateRepositoryExtended>();

By addressing these issues, you should be able to successfully modify the price validation rule and override the behavior of the extended repository. Let me know if you have any questions or need further assistance!

If it doesn’t help, ping me and will extend sample with CartAggregateRepositoryExtended.

Here the step by step solution:

  1. Create a new virto commerce module. Tutorials - Creating Custom Module from Template

  2. Add Reference on VirtoCommerce.XPurchase.dll into Data project.


  1. Register dependency on VirtoCommerce.ExperienceApi into module.manfiest. Adjust platform and module version if required. It allows to run your custom module after VirtoCommerce.ExperienceApi.

    <dependency id="VirtoCommerce.ExperienceApi" version="3.800.0" />
  1. Create CartAggregateRepositoryExtended class.

  1. Register CartAggregateRepositoryExtended in DI during module initialization.

  1. Implement your extension. Build, and Install into platform.

  2. Run Platfromand and Attach Debuger to dotnet process, if required