Update Path for Virto Commerce 3.400

We are excited to announce a significant improvement in 3.400 platform release with the refactoring and simplification of the CRUD (Create, Read, Update, Delete) Services. These changes bring enhanced performance and a more streamlined experience with:

  1. Crud Services were refactored and simplified. To optimize the codebase and improve maintainability, we have removed obsolete methods from the CRUD Services. Use IList Interface (System.Collections.Generic) for input and output parameters.
  2. Refactored CrudService: The VirtoCommerce.Platform.Data.GenericCrud.CrudService has undergone a refactoring process, making it more efficient and easier to work with.
  3. Refactored SearchService: Similarly, the VirtoCommerce.Platform.Data.GenericCrud.SearchService has been refactored, resulting in improved search functionality.
  4. Simplified Interfaces: To enhance usability, the IXXXService interfaces have been restructured to inherit from ICrudService and ISearchService. This simplification streamlines the usage of these services
  5. Introducing GetNoCloneAsync: To optimize performance and retrieval of raw or read-only objects, we have introduced the GetNoCloneAsync method. This addition allows for faster access to specific data when cloning is not necessary.

But 3.400 brings breaking changes, if you are installing version 3.400+ of the platform, you will need to follow these steps.

Note: You can use this PR as a sample PT-10449: Resolves breaking changes with 3.400 by - VirtoCommerce/vc-module-native-payment-methods (github.com)

:one: Sequence for Updating Projects

To smoothly update your projects, we recommend following this sequence: Core, Data, Web, and Test. This sequence will help you avoid potential compatibility issues and ensure a seamless upgrade process.

:two: Upgraded Virto Commerce NuGet:

Update VirtoCommerce NuGet packages to version 3.400.0

:three: Compilation Error Resolution:

During the update process, you may encounter compilation errors related to IEnumerable and ICollection. Please make sure to change them to IList, as Virto Commerce uses IList as the preferred type for collections.

:four: Core Project Changes:

We have introduced interfaces own for Crud and Search operations, simplifying the usage of Generic interfaces.

Instead of ICrudService and ISearchService, you need to use INativePaymentMethodsService and INativePaymentMethodsSearchService already inherited from the base interface.

I create INativePaymentMethodsService and INativePaymentMethodsSearchService interfaces in VirtoCommerce.NativePaymentMethods.Core.Services.

using VirtoCommerce.NativePaymentMethods.Core.Models;
using VirtoCommerce.Platform.Core.GenericCrud;

namespace VirtoCommerce.NativePaymentMethods.Core.Services
{
    public interface INativePaymentMethodsService : ICrudService<NativePaymentMethod>
    {
    }
}
namespace VirtoCommerce.NativePaymentMethods.Core.Services
{
    public interface INativePaymentMethodsSearchService : ISearchService<NativePaymentMethodsSearchCriteria, NativePaymentMethodsSearchResult, NativePaymentMethod>
    {
    }
}

:five: Data Project Enhancements:

In the Data project, add the INativePaymentMethodsService and INativePaymentMethodsSearchService interfaces to the implementation class. These interfaces should replace ICrudService and ISearch.

:six: Configuration Update:

You need to add the Options crudOptions to the search NativePaymentMethodsSearchService implementation to pass settings and configuration.

:seven: Conflict Resolution:

As with any major update, there might be conflicts and compilation errors. Please ensure to resolve them during the update process.

:eight: Web Project Changes:

In the Web project, register the implementation for INativePaymentMethodsService and INativePaymentMethodsSearchService in the Dependency Injection container, replacing ICrudService and ISearch.

:nine: Update Module Manifest:

Update the module.manifest file with 3.400.0 and update dependencies accordingly.

:keycap_ten: Test and Release:

After completing all the above steps, run tests to ensure they pass successfully. Once you have tested everything thoroughly, release the module and other artefacts. Don’t forget to test everything on the QA environment.

Summary

We believe that these updates will provide a more robust and efficient solution for your Virto Commerce modules. As always, if you encounter any issues or have any questions, feel free to reach out to our community or support channels.

Also we added extensions methods to simplify Crud Operations in VirtoCommerce.Platform.Core.Common:

namespace VirtoCommerce.Platform.Core.Common;

    /// <summary>
    /// Returns data from the cache without cloning. This consumes less memory, but the returned data must not be modified.
    /// </summary>
    public static Task<IList<TModel>> GetNoCloneAsync<TModel>(this ICrudService<TModel> crudService, IList<string> ids, string responseGroup = null)
        where TModel : Entity;

    /// <summary>
    /// Returns data from the cache without cloning. This consumes less memory, but the returned data must not be modified.
    /// </summary>
    public static Task<TModel> GetNoCloneAsync<TModel>(this ICrudService<TModel> crudService, string id, string responseGroup = null);

    public static async Task<TModel> GetByIdAsync<TModel>(this ICrudService<TModel> crudService, string id, string responseGroup = null, bool clone = true);

You can find the source in vc-platform/src/VirtoCommerce.Platform.Core/Extensions/CrudServiceExtensions.cs at dev · VirtoCommerce/vc-platform (github.com)

After updating platform NuGet packages to version 3.400, you may receive compilation warnings like the following:

Warning CS0618 'SettingsExtension.GetValueAsync<T>(ISettingsManager, string, T)' is obsolete: 'Use GetValueAsync<>(SettingDescriptor)'

To fix this, you should pass the setting descriptor to the GetValueAsync() instead of the setting name and default value.

Before:
var sendDiagnosticData = settingsManager.GetValue(Setup.SendDiagnosticData.Name, (bool)Setup.SendDiagnosticData.DefaultValue);

After:
var sendDiagnosticData = settingsManager.GetValue<bool>(Setup.SendDiagnosticData);

1 Like