How to create a new module for Virto Commerce Platform v3 from scratch? Follow the steps to create a “Dummy module”.
1. Create a well-structured solution and projects
- Create empty DummyModule solution: https://docs.microsoft.com/en-us/visualstudio/get-started/tutorial-projects-solutions?view=vs-2019##create-a-solution
- Add src and tests Solution Folders (using Visual Studio)
- In src add project using “Class library (.NET Core)” template:
- Project name: DummyModule.Core
- Location: …\DummyModule\src folder (create the missing src folder).
- Add DummyModule.Data and DummyModule.Web projects in the same way, just ensure they are located under src folder.
- Delete the auto-generated Class1.cs from all projects.
- In tests add project using “xUnit Test Project (.NET Core)” template:
- Project name: DummyModule.Tests
- Location: …\DummyModule\tests folder (create the missing tests folder).
- Set “Target framework” to “.NET Core 2.2” for all 4 projects.
- References to projects:
- DummyModule.Data: add reference to DummyModule.Core project
- DummyModule.Web: add references to DummyModule.Core, DummyModule.Data projects
- DummyModule.Tests: add references to DummyModule.Core, DummyModule.Data, DummyModule.Web projects
- References to NuGet packages:
- DummyModule.Core: add reference to latest version 3 (3.x) VirtoCommerce.Platform.Core package.
- DummyModule.Data: add reference to latest version 3 (3.x) VirtoCommerce.Platform.Data package.
- References to NuGet packages in VirtoCommerce.Platform.Web:
- (Double click in Visual Studio to) open DummyModule.Web.csproj file for editing;
- Add new ItemGroup:
<ItemGroup> <PackageReference Include="Microsoft.AspNetCore.App" /> </ItemGroup>
- Compile the solution (there should be no warnings).
2. DummyModule.Core
- ModuleConstants.cs (permissions, settings)
- Models
- Services
- Events
- Notifications
3. DummyModule.Data
- Models
- Repositories
- DbContext
- DesignTimeDbContextFactory,
- IRepository, Repository
- Migrations
- Caching
- Services
- ExportImport
- Handlers
- Search
- Authorization (resource based authorization). Sample: https://github.com/VirtoCommerce/vc-module-store/tree/release/3.0.0/src/VirtoCommerce.StoreModule.Data/Authorization
4. DummyModule.Web
- module.manifest
- JsonConverters
- Module.cs
- API controllers
- Content
- Scripts
- webPack: https://github.com/VirtoCommerce/vc-module-order/blob/release/3.0.0/src/VirtoCommerce.OrdersModule.Web/webpack.config.js
- Localizations
5. DummyModule.Tests
- Unit tests
- Integration tests
6. Pack the module (using VirtoCommerce.GlobalTool)
- dotnet tool install VirtoCommerce.GlobalTool -g --version 3.0.0-beta0008
- copy and edit .nuke
- vc-build compress