Note

OpenDDD.NET is currently in beta. Features and documentation are under active development and subject to change.

Configuration Guide

OpenDDD.NET provides a flexible configuration system to set up persistence, messaging, event handling, and auto-registration.

Configuration is typically done via appsettings.json or by using fluent methods in OpenDddOptions.

JSON Configuration

An example configuration in appsettings.json:

{
  "OpenDDD": {
    "PersistenceProvider": "OpenDdd",
    "DatabaseProvider": "InMemory",
    "MessagingProvider": "InMemory",
    "Events": {
      "DomainEventTopic": "Bookstore.Domain.{EventName}",
      "IntegrationEventTopic": "Bookstore.Interchange.{EventName}",
      "ListenerGroup": "Default"
    },
    "SQLite": {
      "ConnectionString": "DataSource=Infrastructure/Persistence/EfCore/Bookstore.db;Cache=Shared"
    },
    "Postgres": {
      "ConnectionString": "Host=localhost;Port=5432;Database=bookstore;Username=postgres;Password=password"
    },
    "AzureServiceBus": {
      "ConnectionString": "Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=your-key-name;SharedAccessKey=your-key",
      "AutoCreateTopics": true
    },
    "RabbitMq": {
      "HostName": "localhost",
      "Port": 5672,
      "Username": "guest",
      "Password": "guest",
      "VirtualHost": "/",
      "AutoCreateTopics": true
    },
    "Kafka": {
      "BootstrapServers": "localhost:9092",
      "AutoCreateTopics": true
    },
    "AutoRegister": {
      "Actions": true,
      "DomainServices": true,
      "Repositories": true,
      "InfrastructureServices": true,
      "EventListeners": true,
      "EfCoreConfigurations": true,
      "Seeders": true
    }
  }
}

Fluent Configuration

Instead of using appsettings.json, OpenDDD.NET can be configured dynamically in Program.cs:

builder.Services.AddOpenDDD(builder.Configuration,
    options =>
    {
        options.UseInMemoryDatabase()
               .UseInMemoryMessaging()
               .SetEventTopics(
                   "Bookstore.Domain.{EventName}",
                   "Bookstore.Interchange.{EventName}"
                )
               .SetEventListenerGroup("Default")
               .EnableAutoRegistration();
    }
);

Persistence Configuration

OpenDDD.NET supports multiple persistence providers. Each persistence provider supports a set of database providers.

Example Configurations:

OpenDDD Persistence Provider:

// With PostgreSQL
options.UsePostgres("Host=localhost;Port=5432;Database=bookstore;Username=postgres;Password=password");

// With In-Memory
options.UseInMemory();

EF Core Persistence Provider:

// With SQLite
options.UseEfCore().UseSQLite("DataSource=Bookstore.db;Cache=Shared");

// With PostgreSQL
options.UseEfCore().UsePostgres("Host=localhost;Port=5432;Database=bookstore;Username=postgres;Password=password");

// With SQL Server
options.UseEfCore().UseSqlServer("Server=localhost;Database=bookstore;User Id=sa;Password=password;");

Messaging Configuration

OpenDDD.NET supports multiple messaging providers:

In-Memory Messaging:

options.UseInMemoryMessaging();

RabbitMQ:

options.UseRabbitMq(
    hostName: "localhost",
    port: 5672,
    username: "guest",
    password: "guest",
    virtualHost: "/",
    autoCreateTopics: true
);

Kafka:

options.UseKafka(
    "localhost:9092",
    autoCreateTopics: true
);

Azure Service Bus:

options.UseAzureServiceBus(
    "Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=your-key-name;SharedAccessKey=your-key",
    autoCreateTopics: true
);

Event Configuration

Event settings define how domain and integration events are published:

options.SetEventTopics(
          "Bookstore.Domain.{EventName}",
          "Bookstore.Interchange.{EventName}"
       )
       .SetEventListenerGroup("Default");

Auto-Registration

OpenDDD.NET can automatically register key components:

options.EnableAutoRegistration();

To disable auto-registration:

options.DisableAutoRegistration();

You can also configure individual registrations:

{
  "OpenDDD": {
    "AutoRegister": {
      "Actions": true,
      "DomainServices": true,
      "Repositories": true,
      "InfrastructureServices": true,
      "EventListeners": true,
      "EfCoreConfigurations": true,
      "Seeders": true
    }
  }
}

Next Steps