Part 4 - Template Variables

If you are following along with the ArtistSite tutorial, you’ll want to follow these configuration guidelines to produce the same result as us.

In many values, you may see another variable’s name within curly-braces as part of a variable’s value - CodeGenHero can interpolate variable values similarly to how string-interpolation works in C#, allowing you to use Template Variables to construct other Template Variables. In a similar principle “[tablename]” is a template-assigned “system variable” token mapping out to an entity’s name, ie “Customer”.

ArtistSite Template Variables

In the CodeGenHero Blazor template bundle used for the ArtistSite sample, the majority of variables are intended to be promoted to Global - We’ll go over those first and then talk about the remaining Template-specific variables below.

IdentityServer Template
AAD Template

For more information on each variable below, hover over their name in CodeGenHero to see their description. Variables left at default values for our ArtistSite example will be italicized, and customized onces in bold, for brevity.


  • AdminEditViewModelClassName: {namespacePostfix}[tablename]EditViewModel
  • AdminListPageViewModelClassName: {namespacePostfix}[tablepluralname]ListViewModel
  • AdminPageNamespace: {AppPageViewModelsNamespace}.Admin
  • APIControllerClassName: [tablename]Controller
  • APIControllerNamespace: {BaseNamespace}.Api.Controllers
  • ApiRelativeURL: api/{namespacePostfix}
  • ApplicationProjectName: App
  • AppPageViewModelsNamespace: {BaseNamespace}.{ApplicationProjectName}.Pages
  • AutoMapperProfileClassName: {namespacePostfix}AutoMapperProfile
  • BaseAPIControllerClassName: {namespacePostfix}BaseApiController
  • BaseNamespace: MSC.ArtistSite
    • By naming our project “MSC.ArtistSite” on creation earlier, the base namespace of the solution is “MSC.ArtistSite”, so we set the CodeGenHero variable to match it.
  • DbContextName: ArtistSiteDbContext
    • This is the name of the DbContext class that was generated when we created our Metadata. Since we named it ArtistSiteDbContext, we will provide that name here.
  • DtoNamespace: {BaseNamespace}.Shared.DTO
  • EntitiesNamespace: {BaseNamespace}.Repository.Entities
  • GenericFactoryClassName: {namespacePostfix}GenericFactory
  • GenericFactoryInterfaceClassName: I{namespacePostfix}GenericFactory
  • MappersNamespace: {BaseNamespace}.Repository.Mappers
  • NamespacePostfix: AS
    • Intended to be used as something to differentiate between different Metadata sources being generated against in the same Solution, by adding this identifier to names that could potentially be common between different sources. We’ll set this to “AS” for “ArtistSite”, which is the name of the sample database.
  • RepositoryCrudInterfaceClassName: I{namespacePostfix}RepositoryCrud
  • RepositoryInterfaceClassName: I{namespacePostfix}Repository
  • RepositoryNamespace: {BaseNamespace}.Repository.Repositories
  • WebApiDataServiceClassName: WebApiDataService{namespacePostfix}
  • WebApiDataServiceInterfaceClassName: IWebApiDataService{namespacePostfix}
  • WebApiDataServiceNamespace: {BaseNamespace}.{ApplicationProjectName}.Services

In our examples above, we left most of our values at their defaults, with our only changes being to set the NamespacePostfix to identify what was generated based off the database, and the BaseNamespace to match what Visual Studio set at project creation. Due to their global scope, you can change these freely and still produce a compilable result.


Two common variables in every template are “RegexExclude” and “RegexInclude” - These two, respectively, are used to tell a Template to ignore certain Entity types, or include one otherwise caught in the exclusion filter, as part of their code generation by using Regular Expressions to filter entities by their name. We recommend these not be promoted to Global so that you can use them in a fine-grained manner.


The below variables are individual template variables we did not promote to Global, explaining what they are for and how we set them.


APIStatusController

ApiStatusControllerClassName: {namespacePostfix}ApiStatusController

This variable is the name of the class for the API Status Controller


API Controller

MaxRequestPerPageOverrideByTableName: [Blank]

This variable is a JSON-based list of entities used to override and customize the default page-size (Set to 100) that an API Controller’s Get Page methods would return - For simplicity’s sake we’ll leave this empty by default. For more information see the documentation for the CodeGenHero Blazor6 Template Bundle.


AutoMapperProfile

IncludeEntityNavigations: False


ExcludedNavigationRegex: [Blank]

This variable is a RegEx pattern used to exclude foreign-key navigations from being generated for the AutoMapper Profile class. We have no reason to exclude any navigations, so we’ll leave this default as blank.


IncludedNavigation: [Blank]

This is used to mask out entities from being caught by the previous RegEx variable. As we exclude nothing, we have no need to set this.


DTO

IncludeRelatedObjects: True

This boolean variable determines if foreign-key objects will be generated as member properties in your DTOs. We will want these for the site, so leave this as-is.


BaseAPIController

AuthorizedController: False

Adds the Authorize attribute to the top of API Controllers if true, and the AllowAnonymous attribute if false. We’ll keep this as False by default, as API methods that need to be secured can have the Authorize attribute added to them as appropriate.


AutoInvalidateCacheOutput: False

Adds the AutoInvalidateCacheOutput to the Base Controller if true.


Repository

RepositoryClassName: {namespacePostfix}Repository

This variable is the name of your generated Repository class.


WebApiDataService

CheckForIsActiveRegex: [Blank]

Used for entities with a “Soft Delete” functionality that uses an “IsActive” flag. Adding the names of these entities will add a check for if “IsActive” is true as part of their Get methods.



MSC Technology Consulting #MSCTek


Copyright © MSC Technology Consulting 2021.3.2

An error has occurred. This application may no longer respond until reloaded. Reload 🗙