appsettings.json
- Do no store sensitive information, especially passwords in appsettings.json, use the Secret Manager. Please see Safe storage of app secrets in development in ASP.NET Core for reference.
Models
- Store all business class data models under <ProjectName>.Business/Models
- Store all Kentico generated classes under <ProjectName>.Business/Models/Generated. No need to create subfolders unless the number of models is greater than 20, then logically group them in subfolders.
- No need to add Dto in the class name, example HomePage, not HomePageDto
- Name the model class the same as the Kentico Generated class, you just have a different namespace
- Kentico Generated Class: CMS.DocumentEngine.Types.<ProjectName>.HomePage
- Business Model Class: <ProjectName>.Business.Models.HomePage
Repositories
-
Store all repositories under <ProjectName>.Business/Repositories. No need to create subfolders unless the number of repositories is greater than 20, then logically group them in subfolders.
-
Always inherit from XperienceAdapter.Repositories.BasePageRepository<<BusinessClass>, <GeneratedClass>>
public class HomePageRepository : BasePageRepository<HomePage, CMS.DocumentEngine.Types.<ProjectName>.HomePage>
-
If custom methods are needed to simplify data access to repositories, create an interface for the repository and have the repository inherit from both the interface and BasePageRepository.
public interface IHomePageRepository { public HomePage GetHomePage(); } public class HomePageRepository : BasePageRepository<HomePage, CMS.DocumentEngine.Types.<ProjectName>.HomePage>, IHomePageRepository { public HomePage GetHomePage() { .... } }
Navigation
- Basic Navigation - Register
NavigationRepository<NavigationItem>
asINavigationRepository<NavigationItem>
in the dependency injection container, e.g. AutoFac - CustomNavigation - Create a custom NavigationItem DTO and repository. See sample implementations in TestMenuPageDto and TestMenuPageRepository. You can then register
NavigationRepository<TestMenuPageDto>
asNavigationRepository<TestMenuPageDto>
in the dependency injection container.
Unit Testing
- Create unit tests for all repositories with custom methods, otherwise, not needed
- Create unit tests for all components, mock repositories if retrieving data for the component