Wrapt Documentation

website·Indexed 33 days ago

https://wrapt.dev/docs/

Wrapt provides scaffolding tools and documentation for .NET development, primarily through the Craftsman CLI. It enables developers to reduce boilerplate by scaffolding Web API files, database entities, and event-driven architectures using MassTransit and RabbitMQ. The platform includes guides on integration testing with Docker, Duende BFF integration with React, and implementing domain events and background jobs with Hangfire.

Tokens
42.7K
Snippets
168
Records
244
Agent score
66%

What's inside Wrapt

  1. Overview of Wrapt Web API capabilities

    Wrapt is a scaffolding tool designed to eliminate boilerplate for Web APIs, enabling faster deployment through automated generation of core infrastructure. Key features include:

    • Automated HTTP Endpoint Generation
    • Implementation of Vertical Slice Architecture
    • Built-in Filtering, Sorting, and Pagination
    • Generation of Unit, Integration, and Functional Tests
    • Docker-based Database Tests
    • Enhanced Swagger Documentation
    • Auth Server Scaffolding
    • API Versioning and Flexible Validation
    • Serilog Logging and Customizable Response Wrappers
    • Authorization and Scope Protection
    • Pub/Sub Scaffolding using MassTransit
    • Flexible Database Options
  2. Overview of Hangfire in Wrapt

    Hangfire is used in Wrapt projects to perform background tasks out of process, such as migrating legacy data, sending emails, or data processing. It is intended for inter-boundary concerns (tasks within a single boundary) rather than communication between different boundaries (where a message broker like RabbitMQ is preferred). By default, Wrapt projects use in-memory storage for Hangfire, but this can be configured to use SQL Server or other storage options.
  3. Implement a BaseEntity for capturing Domain Events

    To decouple entities in a DDD architecture, create a BaseEntity that tracks domain events. This entity uses a list to queue events that should be published after the entity is persisted to the database. The DomainEvents list is marked with [NotMapped] to prevent EF Core from attempting to persist the event list to the database.
    namespace RecipeManagement.Domain;
    
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using MediatR;
    
    public interface IDomainEvent : INotification { }
    
    public abstract class BaseEntity
    {
    	[Key]
        public Guid Id { get; private set; } = Guid.NewGuid();
    
        [NotMapped]
        public List<IDomainEvent> DomainEvents { get; } = new List<IDomainEvent>();
    
        public void QueueDomainEvent(IDomainEvent @event)
        {
            DomainEvents.Add(@event);
        }
    }
  4. Understand the Wrapt framework and Craftsman CLI

    Wrapt is a .NET framework designed to eliminate repetitive Web API setup by using a companion CLI tool called Craftsman. Craftsman scaffolds an entire Web API based on a yaml or json description file. A Wrapt project is a standard .NET solution organized in a specific structure that allows the Craftsman CLI to automate the addition of boilerplate code, enabling developers to focus on business logic rather than infrastructure setup.
  5. Implement Features using MediatR

    Features are the core of Wrapt's Vertical Slice Architecture and are located in the Domain/Feature folder. Each feature corresponds to an action performed on an entity. Wrapt provides default CRUD features (Get List, Get Record, Create, Update, Partial Update, and Delete). Technically, features are implemented as MediatR commands or queries handled by a handler that returns a response. Controllers act solely as routers to these features.
  6. Communicate between bounded contexts using MassTransit

    In Wrapt projects, bounded contexts can communicate either in-process via REST requests or out-of-process using a message broker. The recommended pattern for decoupled communication is event-driven: one bounded context publishes a notification that an event occurred, and one or more other bounded contexts consume that notification to perform subsequent actions.
  7. Understand Wrapt Project Architecture

    Wrapt projects utilize a Vertical Slice Architecture (VSA). Unlike Clean/Onion architectures that separate code by technical layers, VSA organizes code by features to minimize sharing between features and ensure that new functionality rarely requires updating existing code. This approach adheres to YAGNI (You Ain't Gonna Need It) and KISS (Keep It Simple Stupid) principles, where reusable code is abstracted only after a genuine need is discovered.
  8. Scaffold Pub/Sub messages, producers, and consumers

    Craftsman provides CLI commands to scaffold event-driven architecture components: add:message for defining the message contract, add:producer for the publisher, and add:consumer for the subscriber. These can be run as standalone commands or defined within a new:domain template.
    DomainName: VsaLab
    Messages:
    - Name: IPatientUpdated
      Properties:
      - Name: PatientId
        Type: guid
    BoundedContexts:
      Bus:
        AddBus: true
      Producers:
      - EndpointRegistrationMethodName: PatientUpdatedEndpoint
        ExchangeName: patient-updated
        MessageName: IPatientUpdated
        ExchangeType: fanout
        ProducerName: PatientUpdated
      Consumers:
      - EndpointRegistrationMethodName: SyncPatientEndpoint
        ConsumerName: SyncPatient
        ExchangeName: patient-updated
        MessageName: IPatientUpdated
        QueueName: sync-billing-patient
        ExchangeType: fanout
  9. Understand Event-Driven Architecture (EDA) vs Event Sourcing

    Event-Driven Architecture (EDA) is a pattern used in distributed applications to notify other services of state changes via events (e.g., CustomerAddressUpdated). This allows other applications to react to those changes independently. In contrast, Event Sourcing is a pattern where the current state of an entity is derived entirely from the full history of events that have occurred to it over time.
  10. Understand permission levels in .NET applications

    When designing authorization, it is useful to differentiate between three levels of permissions:

    1. Application Access: Configured in the auth server and passed via tokens (e.g., using the aud claim) to determine which APIs a token can access.
    2. Feature Access: Permission-specific checks within a particular application boundary (e.g., whether a user can perform a specific action).
    3. Application Logic: Custom business logic specific to the application (e.g., criteria-based access control).
  11. Implement Value Objects in Wrapt projects

    Value Objects are used to group related attributes and behaviors. Unlike entities, they do not have a unique identity (key); equality is based solely on the values of their attributes. To ensure domain integrity, Value Objects must protect themselves from invalid states by validating data in constructors, factory methods, or property initializers. They can also be composed of other Value Objects.
  12. Understand the message flow in an Event-Driven Architecture

    The standard flow for a message in an event-driven system using a broker is as follows:

    1. An application publishes a message to the broker.
    2. The message enters the exchange.
    3. The exchange evaluates the message configuration.
    4. The exchange routes the message to the appropriate queue(s) based on established bindings.
    5. The message resides in the queue until a consumer is available.
    6. One or more subscribing applications consume the message from the queue.