Skip to main content

Overview

The Intent.AI.AutoImplementation module uses AI to automatically implement the Handler method of a Command or Query, based on the full context provided by generated code and model metadata from Intent Architect. This module leverages Large Language Models (LLMs) to generate production-ready business logic by analyzing your domain entities, repository interfaces, DTOs, and service contracts.
To use this feature, ensure that the required User Settings have been completed — including a valid API key for your selected AI provider.

What Gets Generated

Handler Implementations

The AI analyzes your application context and generates:
  • Complete handler method implementation with all business logic
  • Repository interactions for data access
  • Entity mapping between DTOs and domain models
  • Validation logic when appropriate
  • Error handling for common scenarios
  • Proper async/await patterns
Example generated implementation:
Application/Customers/CreateCustomer/CreateCustomerCommandHandler.cs
public class CreateCustomerCommandHandler : IRequestHandler<CreateCustomerCommand, Guid>
{
    private readonly ICustomerRepository _customerRepository;

    public CreateCustomerCommandHandler(ICustomerRepository customerRepository)
    {
        _customerRepository = customerRepository;
    }

    [IntentManaged(Mode.Fully, Body = Mode.Ignore)]
    public async Task<Guid> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
    {
        // AI-generated implementation
        var customer = new Customer
        {
            Name = request.Name,
            Email = request.Email,
            PhoneNumber = request.PhoneNumber,
            Address = request.Address
        };

        _customerRepository.Add(customer);
        await _customerRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

        return customer.Id;
    }
}

Installation

Prerequisites

  • An Intent Architect application with Commands or Queries
  • An AI provider account (OpenAI, Azure OpenAI, or Anthropic)
  • Valid API key configured in User Settings

Installation Steps

1

Install the module

In Intent Architect, right-click on your application and select Manage Modules. Search for Intent.AI.AutoImplementation and install it.
2

Configure AI provider

Go to ToolsUser SettingsAI Configuration and enter your API key for your chosen provider (OpenAI, Azure OpenAI, or Anthropic).
3

Create your domain model

Design your entities, commands, and queries in Intent Architect.
4

Run the Software Factory

Generate the handler scaffolding and related code.

Usage

Basic Workflow

1

Model your Command or Query

In the Services Designer, create a Command or Query with the appropriate mapping to your domain entities.
2

Run the Software Factory

Execute the Software Factory to generate the handler class with an empty Handle method.
3

Right-click and Implement with AI

In the Services Designer, right-click on your Command or Query and select Implement with AI.Auto Implement Menu
4

Review and apply changes

The AI will generate the implementation and show you a diff. Review and apply the changes.

Influencing Factors

The quality and relevance of the generated implementation depend on several factors.

Intent Modeling

Before running Implement with AI, ensure the following:
  • Generated Code is up-to-date: Run the Software Factory to apply all outstanding code changes
  • Command/Query is mapped: Ensure the Command or Query is associated with the appropriate Entity using a Create Entity, Update Entity, or Query Entity action (a dotted line should appear between the elements)
  • Repository interfaces exist: Make sure repository templates have been generated
  • DTOs are properly mapped: For queries, ensure return types map correctly to entities

Adjusting the Prompt

While Intent Architect supplies a default prompt and relevant file context to the AI provider, you can optionally provide additional context to refine the result. Add custom instructions: Additional Prompt Example prompts:
Ensure that duplicate email addresses are checked before creating the customer.
Include soft delete logic - set the IsDeleted flag instead of removing the entity.
Add logging before and after the operation using ILogger.
It’s recommended to try the default implementation first. If needed, rerun with added context to improve results.
AI responses are not deterministic — each execution may produce different results. Use the additional context prompt to guide the AI toward your desired implementation.

Examples

Create Command Implementation

Modeled Command:
  • Command: CreateOrderCommand
  • Mapping: Create EntityOrder
  • Properties: CustomerId, OrderItems[]
AI-Generated Implementation:
Application/Orders/CreateOrder/CreateOrderCommandHandler.cs
public async Task<Guid> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
{
    var customer = await _customerRepository.FindByIdAsync(request.CustomerId, cancellationToken);
    if (customer == null)
    {
        throw new NotFoundException($"Customer with ID {request.CustomerId} not found");
    }

    var order = new Order
    {
        CustomerId = request.CustomerId,
        OrderDate = DateTime.UtcNow,
        Status = OrderStatus.Pending
    };

    foreach (var item in request.OrderItems)
    {
        var product = await _productRepository.FindByIdAsync(item.ProductId, cancellationToken);
        if (product == null)
        {
            throw new NotFoundException($"Product with ID {item.ProductId} not found");
        }

        order.AddOrderItem(new OrderItem
        {
            ProductId = item.ProductId,
            Quantity = item.Quantity,
            UnitPrice = product.Price
        });
    }

    _orderRepository.Add(order);
    await _orderRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

    return order.Id;
}

Update Command Implementation

Modeled Command:
  • Command: UpdateCustomerCommand
  • Mapping: Update EntityCustomer
  • Properties: Id, Name, Email, PhoneNumber
AI-Generated Implementation:
Application/Customers/UpdateCustomer/UpdateCustomerCommandHandler.cs
public async Task Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
{
    var customer = await _customerRepository.FindByIdAsync(request.Id, cancellationToken);
    if (customer == null)
    {
        throw new NotFoundException($"Customer with ID {request.Id} not found");
    }

    customer.Name = request.Name;
    customer.Email = request.Email;
    customer.PhoneNumber = request.PhoneNumber;

    await _customerRepository.UnitOfWork.SaveChangesAsync(cancellationToken);
}

Query Implementation

Modeled Query:
  • Query: GetCustomerByIdQuery
  • Mapping: Query EntityCustomer
  • Return Type: CustomerDto
AI-Generated Implementation:
Application/Customers/GetCustomerById/GetCustomerByIdQueryHandler.cs
public async Task<CustomerDto> Handle(GetCustomerByIdQuery request, CancellationToken cancellationToken)
{
    var customer = await _customerRepository.FindByIdAsync(request.Id, cancellationToken);
    if (customer == null)
    {
        throw new NotFoundException($"Customer with ID {request.Id} not found");
    }

    return new CustomerDto
    {
        Id = customer.Id,
        Name = customer.Name,
        Email = customer.Email,
        PhoneNumber = customer.PhoneNumber,
        Address = customer.Address,
        TotalOrders = customer.Orders.Count
    };
}

Complex Business Logic

Custom Prompt:
Implement order approval logic. Check if the total amount exceeds $10,000.
If it does, set status to PendingApproval. Otherwise, set to Approved.
Send an email notification if approval is required.
AI-Generated Implementation:
Application/Orders/ApproveOrder/ApproveOrderCommandHandler.cs
public async Task Handle(ApproveOrderCommand request, CancellationToken cancellationToken)
{
    var order = await _orderRepository.FindByIdAsync(request.OrderId, cancellationToken);
    if (order == null)
    {
        throw new NotFoundException($"Order with ID {request.OrderId} not found");
    }

    var totalAmount = order.OrderItems.Sum(item => item.Quantity * item.UnitPrice);

    if (totalAmount > 10000)
    {
        order.Status = OrderStatus.PendingApproval;
        await _emailService.SendApprovalRequiredEmailAsync(
            order.CustomerId, 
            order.Id, 
            totalAmount, 
            cancellationToken
        );
    }
    else
    {
        order.Status = OrderStatus.Approved;
    }

    await _orderRepository.UnitOfWork.SaveChangesAsync(cancellationToken);
}

Code Changes Review

Once the AI Agent completes the task, suggested code changes will be displayed for review: Recommended Changes You can:
  • Review the diff to see exactly what will change
  • Accept or reject the implementation
  • Rerun with additional context if the result isn’t satisfactory

Execution Output

Full logs of the execution, including the AI prompt and any errors, are available in the Execution tab: Execution Logs This helps you understand:
  • What context was sent to the AI
  • How the AI reasoned about the implementation
  • Any errors or warnings during generation

Best Practices

Model First

Create complete domain models with proper entity relationships before using AI implementation.

Keep Commands Simple

Focus each command on a single responsibility. Complex operations can be split into multiple commands.

Review Generated Code

Always review AI-generated implementations for correctness, security, and alignment with your coding standards.

Iterate with Prompts

Use custom prompts to guide the AI toward specific patterns, validations, or business rules.

Integration with Other Modules

AI Unit Tests

After implementing handlers, use AI to generate comprehensive unit tests.

FluentValidation

Combine with validation modules for input validation before handler execution.

MediatR

Works seamlessly with MediatR-based CQRS implementations.

Entity Framework

Generates proper EF Core repository usage patterns.

Next Steps

AI Unit Tests

Generate tests for your implementations

AI Blazor

Build UI components with AI

Domain Modeling

Learn best practices for domain modeling

Build docs developers (and LLMs) love