.NET Plugin Events
Create Entity Controller Base
Get Started
Lifecycle & Coding Details
Developing a Plugin
Guides & Tutorials
Blueprint Plugin Events
Node.js Plugin Events
- Create Server
- Create Server Docker Compose
- Create Server Docker Compose Dev
- Create Server Dot Env
- Create Server Auth
- Create Package Json
- Create Entity Service
- Create Entity Service Base
- Create Entity Controller
- Create Entity Controller Base
- Create Entity Resolver
- Create Entity Resolver Base
- Create Message Broker Service
- Create Message Broker Service Base
- Create Message Broker NestJS Module
- Create Message Broker Client Options Factory
- Create Message Broker Topics Enum
- Create Prisma Schema
.NET Plugin Events
- Create Server
- Create Server Appsettings
- Create Server Auth
- Create Program File
- Create Server Csproj
- Create Server Docker Compose
- Create Server Git Ignore
- Create Entity Model
- Create Resource Db Context File
- Create Message Broker
- Create Message Broker Client Options Factory
- Create Message Broker Service
- Create Entity Controller
- Create Entity Controller Base
- Create DTOs
- Create Entity Extensions
- Create Entity Interface
- Create Entity Service
- Create Entity Service Base
- Create Seed Development Data File
- Load Static Files
.NET Plugin Events
Create Entity Controller Base
Creates a base controller for entities in the .NET application.
afterCreateEntityControllerBase(
context: dotnetTypes.DsgContext,
eventParams: dotnet.CreateEntityControllerBaseParams,
files: FileMap<Class>
): Promise<FileMap<Class>> {
const { entity, resourceName, apisDir } = eventParams;
const controllerBasePath = `${apisDir}/${entity.name}/Base/${pascalCase(entity.name)}ControllerBase.cs`;
const controllerBaseFile = files.get(controllerBasePath);
if (controllerBaseFile) {
// Add a protected method to the base controller
controllerBaseFile.code.addMethod(
CsharpSupport.method({
name: "ValidateEntityState",
access: "protected",
returnType: CsharpSupport.Types.boolean(),
parameters: [
CsharpSupport.parameter({
name: "entity",
type: CsharpSupport.Types.reference(entity.name),
}),
],
body: `
if (entity == null)
return false;
// Add custom validation logic here
return true;
`,
})
);
// Modify existing methods to use the new validation
const methods = controllerBaseFile.code.getMethods();
methods.forEach(method => {
if (method.name === `Create${entity.name}` || method.name === `Update${entity.name}`) {
const existingBody = method.body;
method.body = `
if (!ValidateEntityState(${camelCase(entity.name)}))
return BadRequest("Invalid entity state");
${existingBody}
`;
}
});
}
return files;
}
Event Name
CreateEntityControllerBase
Event Parameters
The entity object for which the base controller is being created.
The name of the resource (typically the entity name).
The directory where the API controllers are being generated.
An array of module actions available for the entity.
An array of all entities in the application.
afterCreateEntityControllerBase(
context: dotnetTypes.DsgContext,
eventParams: dotnet.CreateEntityControllerBaseParams,
files: FileMap<Class>
): Promise<FileMap<Class>> {
const { entity, resourceName, apisDir } = eventParams;
const controllerBasePath = `${apisDir}/${entity.name}/Base/${pascalCase(entity.name)}ControllerBase.cs`;
const controllerBaseFile = files.get(controllerBasePath);
if (controllerBaseFile) {
// Add a protected method to the base controller
controllerBaseFile.code.addMethod(
CsharpSupport.method({
name: "ValidateEntityState",
access: "protected",
returnType: CsharpSupport.Types.boolean(),
parameters: [
CsharpSupport.parameter({
name: "entity",
type: CsharpSupport.Types.reference(entity.name),
}),
],
body: `
if (entity == null)
return false;
// Add custom validation logic here
return true;
`,
})
);
// Modify existing methods to use the new validation
const methods = controllerBaseFile.code.getMethods();
methods.forEach(method => {
if (method.name === `Create${entity.name}` || method.name === `Update${entity.name}`) {
const existingBody = method.body;
method.body = `
if (!ValidateEntityState(${camelCase(entity.name)}))
return BadRequest("Invalid entity state");
${existingBody}
`;
}
});
}
return files;
}
Was this page helpful?
afterCreateEntityControllerBase(
context: dotnetTypes.DsgContext,
eventParams: dotnet.CreateEntityControllerBaseParams,
files: FileMap<Class>
): Promise<FileMap<Class>> {
const { entity, resourceName, apisDir } = eventParams;
const controllerBasePath = `${apisDir}/${entity.name}/Base/${pascalCase(entity.name)}ControllerBase.cs`;
const controllerBaseFile = files.get(controllerBasePath);
if (controllerBaseFile) {
// Add a protected method to the base controller
controllerBaseFile.code.addMethod(
CsharpSupport.method({
name: "ValidateEntityState",
access: "protected",
returnType: CsharpSupport.Types.boolean(),
parameters: [
CsharpSupport.parameter({
name: "entity",
type: CsharpSupport.Types.reference(entity.name),
}),
],
body: `
if (entity == null)
return false;
// Add custom validation logic here
return true;
`,
})
);
// Modify existing methods to use the new validation
const methods = controllerBaseFile.code.getMethods();
methods.forEach(method => {
if (method.name === `Create${entity.name}` || method.name === `Update${entity.name}`) {
const existingBody = method.body;
method.body = `
if (!ValidateEntityState(${camelCase(entity.name)}))
return BadRequest("Invalid entity state");
${existingBody}
`;
}
});
}
return files;
}