The extension is created to work together with this modular architecture, that is the base for every Strongbytes new project;
You should be familiar with how CQRS Pattern works together with Mediator Pattern to reduce dependencies between objects and separate read and update operations for a data store. We use MediatR in our modular architecture to accomplish this requirement;
You should be familiar with Repository and Unit of Work Pattern. We implemented a Base Repository and a Base Unit of Work in the modular architecture, that can be easily extended;
You should be familiar with IoC. We use Autofac IoC as the IoC Container;
Open your solution and right-click any existing model (eg. LearningPath.cs). Choose Generate Boilerplate Code... from the menu:
A new Window will appear, that contains 3 sections:
Entity Hierarchy Section
Contains a TreeView of the selected entity hierarchy (including all containing models and the base class).
Inside this TreeView you can select which properties cab be used to generate the "Domain Model"
Target Module is used to specify which application module will contain all the generated files (except for Controller and DbContext);
Controller Location us used to specify which module is the main application module (the one where all Controllers are located);
You can specify if you want for the genrated CQRS files to use Unit of Work and Repository implementations (also generated by the extension). If this option is not selected, all CQRS classes will have the application DbContext as a dependency;
You can specify which Queries and which Commands should be generated;
Note: In order for "GetPaginated" operation to be available, the project has to implement IPaginatedDataQuery and IPaginatedDataResponse<T>;
After you fill all the required data, the "Generate Code" button is available.
Directory Structure Section
Contains a TreeView of all the generated (or updated) classes;
All classes are mappend to the corresponding directories;
Generated Files:
LearningPathDomainModel.cs is the generated class that will be sent to the client as the result for all Controller Requests. It contains all the selected properties from Entity Hierarchy. The same properties are used to generated models specific for CQRS Commands (in this case only for CreateLearningPathRequestModel.cs)
ApplicationDbContext.cs will append (if doesn't already exist) the DbSet;
LearningPathsController.cs is the generated API Controller, that contains all the selected Queries and Commands;
LearningPathsMapper.cs contains all the generated object mappings. If the file does not exist, it will be created from scratch. If the file exists, the extension will find the existing mappings and will not replace them;
ILearningPathsRepository.cs is the generated Repository Interface, that implements IBaseRepository<LearningPath>;
LearningPathsRepository.cs is the implementation of the ILearningPathsRepository interface, that inherits from BaseRepository<LearningPath>
IUnitOfWork.cs is an interface that contains all the existing repositories (as interfaces). If the new generated repository (ILearningPathsRepository) does not exist as a property, will be appended. This interface implements IBaseUnitOfWork
UnitOfWork.cs is the class that implements IUnitOfWork interface.
LearningPathsModule.cs is the Autofac module that registers all the services required for the Target Module. The extension will automatically register ILearningPathsRepository, LearningPathsRepository, IUnitOfWork and UnitOfWork (if not already registered);
Commands CreateLearningPathCommand.cs, DeleteLearningPathCommand.cs and Queries GetLearningPathByIdQuery.cs, GetPaginatedLearningPathsQuery.cs implement IRequest<> from MediatR. Every class of this type has a specific CQRS Handler;
All CQRS Handlers provide a Handle() method, where you will need to write your business logic. All handlers have the same dependencies (IUnitOfWork / DbContext for data access and IMapper for objects mapping)