Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CodeGeneratorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void ExecuteAsync(object sender, EventArgs e)
$"{nameofPlural}/Commands/Import/Import{nameofPlural}CommandValidator.cs",
$"{nameofPlural}/Caching/{name}CacheKey.cs",
$"{nameofPlural}/DTOs/{name}Dto.cs",
$"{nameofPlural}/Mappers/{name}Mapper.cs",
/*$"{nameofPlural}/Mappers/{name}Mapper.cs",*/
$"{nameofPlural}/EventHandlers/{name}CreatedEventHandler.cs",
$"{nameofPlural}/EventHandlers/{name}UpdatedEventHandler.cs",
$"{nameofPlural}/EventHandlers/{name}DeletedEventHandler.cs",
Expand Down
17 changes: 14 additions & 3 deletions src/Templatemap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static async Task<string> GetTemplateFilePathAsync(Project project, Intel
"Commands\\AddEdit",
"Commands\\Import",
"DTOs",
"Mappers",
/*"Mappers",*/
"Caching",
"EventHandlers",
"Events",
Expand Down Expand Up @@ -149,7 +149,7 @@ private static async Task<string> ReplaceTokensAsync(Project project, Intellisen
var mudTdHeaderDefinition = createMudTdHeaderDefinition(classObject, objectlist);
var mudFormFieldDefinition = createMudFormFieldDefinition(classObject, objectlist);
var readonlyFieldDefinition = createReadyonlyFieldDefinition(classObject, objectlist);
var fieldAssignmentDefinition = createFieldAssignmentDefinition(classObject);
var fieldAssignmentDefinition = createFieldAssignmentDefinition(classObject, objectlist);
var entityTypeBuilderConfirmation = createEntityTypeBuilderConfirmation(classObject, objectlist);
var commandValidatorRuleFor = createComandValidatorRuleFor(classObject, objectlist);
var replacements = new Dictionary<string, string>
Expand Down Expand Up @@ -655,13 +655,24 @@ private static string createReadyonlyFieldDefinition(IntellisenseObject classObj
return output.ToString();
}

private static string createFieldAssignmentDefinition(IntellisenseObject classObject)
private static string createFieldAssignmentDefinition(IntellisenseObject classObject, IEnumerable<IntellisenseObject> objectlist = null)
{
var output = new StringBuilder();
foreach (var property in classObject.Properties.Where(x => x.Type.IsKnownType == true && x.Name != "Id"))
{
output.Append($" {property.Name} = dto.{property.Name}, \r\n");
}
foreach(var property in classObject.Properties.Where(x => x.Type.IsKnownType == false && x.Name != "Id"))
{
if (objectlist != null)
{
var relatedObject = objectlist.FirstOrDefault(x => x.FullName.Equals(property.Type.CodeName) && x.IsEnum);
if (relatedObject != null)
{
output.Append($" {property.Name} = dto.{property.Name}, \r\n");
}
}
}
return output.ToString();
}

Expand Down
43 changes: 21 additions & 22 deletions src/Templates/Commands/AddEdit/.cs.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file is part of the CleanArchitecture.Blazor project.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// Author: {author}
// Created Date: {createddate}
// Last Modified: {createddate}
// Description:
// This file defines the command for adding or editing a {itemnamelowercase} entity,
// including validation and mapping operations. It handles domain events
// and cache invalidation for updated or newly created {itemnamelowercase}.
//
// Documentation:
// https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// CleanArchitecture.Blazor - MIT Licensed.
// Author: {author}
// Created/Modified: {createddate}
// Command for adding/editing a {itemnamelowercase} entity with validation, mapping,
// domain events, and cache invalidation.
// Documentation: https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// </auto-generated>
//------------------------------------------------------------------------------

// Usage:
// This command can be used to add a new {itemnamelowercase} or edit an existing one.
// It handles caching logic and domain event raising automatically.
// Usage: Use this command to add or edit a {itemnamelowercase}. Caching and domain event handling are automatic.


using {selectns}.{nameofPlural}.Caching;
using {selectns}.{nameofPlural}.Mappers;

using {selectns}.{nameofPlural}.DTOs;
namespace {namespace};

public class AddEdit{itemname}Command: ICacheInvalidatorRequest<Result<int>>
Expand All @@ -36,14 +24,25 @@ public class AddEdit{itemname}Command: ICacheInvalidatorRequest<Result<int>>

public string CacheKey => {itemname}CacheKey.GetAllCacheKey;
public IEnumerable<string>? Tags => {itemname}CacheKey.Tags;
private class Mapping : Profile
{
public Mapping()
{
CreateMap<{itemname}Dto, AddEditContactCommand>(MemberList.None);
CreateMap<AddEdit{itemname}Command, {itemname}>(MemberList.None);
}
}
}

public class AddEdit{itemname}CommandHandler : IRequestHandler<AddEdit{itemname}Command, Result<int>>
{
private readonly IMapper _mapper;
private readonly IApplicationDbContext _context;
public AddEdit{itemname}CommandHandler(
IMapper mapper,
IApplicationDbContext context)
{
_mapper = mapper;
_context = context;
}
public async Task<Result<int>> Handle(AddEdit{itemname}Command request, CancellationToken cancellationToken)
Expand All @@ -55,15 +54,15 @@ public class AddEdit{itemname}CommandHandler : IRequestHandler<AddEdit{itemname}
{
return await Result<int>.FailureAsync($"{itemname} with id: [{request.Id}] not found.");
}
{itemname}Mapper.ApplyChangesFrom(request,item);
item = _mapper.Map(request, item);
// raise a update domain event
item.AddDomainEvent(new {itemname}UpdatedEvent(item));
await _context.SaveChangesAsync(cancellationToken);
return await Result<int>.SuccessAsync(item.Id);
}
else
{
var item = {itemname}Mapper.FromEditCommand(request);
var item = _mapper.Map<Contact>(request);
// raise a create domain event
item.AddDomainEvent(new {itemname}CreatedEvent(item));
_context.{nameofPlural}.Add(item);
Expand Down
25 changes: 7 additions & 18 deletions src/Templates/Commands/AddEdit/.validator.cs.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file is part of the CleanArchitecture.Blazor project.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// Author: {author}
// Created Date: {createddate}
// Last Modified: {createddate}
// Description:
// This file defines the validation rules for the AddEdit{itemname}Command
// used to add or edit {itemname} entities within the CleanArchitecture.Blazor
// application. It enforces maximum field lengths and required properties
// to maintain data integrity and validation standards.
//
// Documentation:
// https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// CleanArchitecture.Blazor - MIT Licensed.
// Author: {author}
// Created/Modified: {createddate}
// Validator for AddEdit{itemname}Command: enforces field length and required property rules for {itemname} entities.
// Docs: https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// </auto-generated>
//------------------------------------------------------------------------------

// Usage:
// This validator enforces constraints on the AddEdit{itemname}Command, such as
// maximum field length for ...
// Validates AddEdit{itemname}Command constraints (e.g., maximum field lengths).


namespace {namespace};

Expand Down
41 changes: 19 additions & 22 deletions src/Templates/Commands/Create/.cs.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file is part of the CleanArchitecture.Blazor project.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// Author: {author}
// Created Date: {createddate}
// Last Modified: {createddate}
// Description:
// This file defines the command and its handler for creating a new {itemname} entity
// within the CleanArchitecture.Blazor application. The command uses caching
// invalidation to ensure data consistency and raises domain events to maintain
// the integrity of the entity lifecycle. It leverages Clean Architecture principles
// for separation of concerns and encapsulation.
//
// Documentation:
// https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// CleanArchitecture.Blazor - MIT Licensed.
// Author: {author}
// Created/Modified: {createddate}
// Command and handler for creating a new {itemname}.
// Uses caching invalidation and domain events for data consistency.
// Docs: https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// </auto-generated>
//------------------------------------------------------------------------------

// Usage:
// This command can be used to create a new {itemnamelowercase} entity in the system. It includes
// the required fields for the {itemnamelowercase} and automatically raises necessary domain
// events for integration with other bounded contexts in the application.
// Use this command to create a new {itemnamelowercase} with required fields and automatic domain event handling.


using {selectns}.{nameofPlural}.Caching;
using {selectns}.{nameofPlural}.Mappers;

namespace {namespace};

Expand All @@ -37,19 +24,29 @@ public class Create{itemname}Command: ICacheInvalidatorRequest<Result<int>>
{dtoFieldDefinition}
public string CacheKey => {itemname}CacheKey.GetAllCacheKey;
public IEnumerable<string>? Tags => {itemname}CacheKey.Tags;
private class Mapping : Profile
{
public Mapping()
{
CreateMap<Create{itemname}Command, {itemname}>(MemberList.None);
}
}
}

public class Create{itemname}CommandHandler : IRequestHandler<Create{itemname}Command, Result<int>>
{
private readonly IMapper _mapper;
private readonly IApplicationDbContext _context;
public Create{itemname}CommandHandler(
IMapper mapper,
IApplicationDbContext context)
{
_mapper = mapper;
_context = context;
}
public async Task<Result<int>> Handle(Create{itemname}Command request, CancellationToken cancellationToken)
{
var item = {itemname}Mapper.FromCreateCommand(request);
var item = _mapper.Map<Contact>(request);
// raise a create domain event
item.AddDomainEvent(new {itemname}CreatedEvent(item));
_context.{nameofPlural}.Add(item);
Expand Down
26 changes: 7 additions & 19 deletions src/Templates/Commands/Create/.validator.cs.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file is part of the CleanArchitecture.Blazor project.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// Author: {author}
// Created Date: {createddate}
// Last Modified: {createddate}
// Description:
// This file defines the validation rules for the Create{itemname}Command,
// used to create {itemname} entities within the CleanArchitecture.Blazor
// application. It ensures that essential fields are validated correctly,
// including maximum lengths and mandatory requirements for required fields.
//
// Documentation:
// https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// CleanArchitecture.Blazor - MIT Licensed.
// Author: {author}
// Created/Modified: {createddate}
// Validator for Create{itemname}Command: enforces max lengths and required fields for {itemname} entities.
// Docs: https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// </auto-generated>
//------------------------------------------------------------------------------

// Usage:
// This validator is used to ensure that a Create{itemname}Command meets the required
// validation criteria. It enforces constraints like maximum field lengths and
// ensures that the Name field is not empty before proceeding with the command execution.
// Validates Create{itemname}Command ensuring constraints (e.g., non-empty Name field) before execution.


namespace {namespace};

Expand Down
30 changes: 9 additions & 21 deletions src/Templates/Commands/Delete/.cs.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file is part of the CleanArchitecture.Blazor project.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// Author: {author}
// Created Date: {createddate}
// Last Modified: {createddate}
// Description:
// This file defines the command and its handler for deleting one or more
// {itemname} entities from the CleanArchitecture.Blazor application. It
// implements caching invalidation logic to ensure that data consistency is
// maintained. Domain events are triggered for deleted entities to support
// integration with other parts of the system.
// for separation of concerns and encapsulation.
//
// Documentation:
// https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// CleanArchitecture.Blazor - MIT Licensed.
// Author: {author}
// Created/Modified: {createddate}
// Command and handler for deleting {itemname} entities.
// Implements cache invalidation and triggers domain events.
// Docs: https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// </auto-generated>
//------------------------------------------------------------------------------

// Usage:
// This command can be used to delete multiple {nameofPlural} from the system by specifying
// their IDs. The handler also raises domain events for each deleted {itemnamelowercase} to
// notify other bounded contexts and invalidate relevant cache entries.
// Delete multiple {nameofPlural} by specifying their IDs.
// Domain events are raised for each deletion to support cache invalidation.


using {selectns}.{nameofPlural}.Caching;

Expand Down
26 changes: 7 additions & 19 deletions src/Templates/Commands/Delete/.validator.cs.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file is part of the CleanArchitecture.Blazor project.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// Author: {author}
// Created Date: {createddate}
// Last Modified: {createddate}
// Description:
// This file defines the validation rules for the Delete{itemname}Command used
// to delete {itemname} entities within the CleanArchitecture.Blazor application.
// It ensures that the command has valid input, particularly verifying that the
// list of {itemnamelowercase} IDs to delete is not null and contains only positive IDs.
//
// Documentation:
// https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// CleanArchitecture.Blazor - MIT Licensed.
// Author: {author}
// Created/Modified: {createddate}
// Validator for Delete{itemname}Command: ensures the ID list for {itemnamelowercase} is not null and contains only positive IDs.
// Docs: https://docs.cleanarchitectureblazor.com/features/{itemnamelowercase}
// </auto-generated>
//------------------------------------------------------------------------------

// Usage:
// This validator ensures that the Delete{itemname}Command is valid before attempting
// to delete {itemnamelowercase} records from the system. It verifies that the ID list is not
// null and that all IDs are greater than zero.
// Validates Delete{itemname}Command by checking that the ID list is non-null and all IDs are > 0.


namespace {namespace};

Expand Down
Loading
Loading