Skip to content

Basic Configuration

quyvu edited this page Oct 14, 2026 · 3 revisions

Basic Configuration

Learn how to configure FxMap in your application with the essential setup steps to get started quickly.

Register FxMap Services

The first step is to register FxMap services in your application's dependency injection container. Add this to your Program.cs file:

using FxMap;
 
builder.Services.AddFxMap(cfg =>
{
    // Register entity configs from your assembly
    cfg.AddEntitiesFromAssemblyContaining<SomeEntityAssemblyMarker>();
 
    // Register DTO profiles from your assembly
    cfg.AddProfilesFromAssemblyContaining<SomeProfileAssemblyMarker>();
});

Add a Data Provider

FxMap needs a data provider to fetch data. Choose the one that matches your database technology.

Entity Framework Core

For SQL databases using EF Core

builder.Services.AddFxMap(cfg => { ... })
    .AddEntityFrameworkCore(options => options.AddDbContexts(typeof(TestDbContext), typeof(OtherDbContext)...)});

MongoDB

For NoSQL databases using MongoDB

builder.Services.AddFxMap(cfg => { ... })
  .AddMongoDb(cfg => cfg.AddCollection(memberSocialCollection));

Add a Transport (Optional)

For microservices architectures, add a transport to enable cross-service communication.

RabbitMQ

builder.Services.AddFxMap(cfg => 
{ 
      // Other configurations 
      cfg.AddRabbitMq(config =>
      {
          config.Host("localhost", "/", 5672, c =>
          {
              c.UserName("guest");
              c.Password("guest");
          });
      });
})

NATS

builder.Services.AddFxMap(cfg => 
{ 
      // Other configurations 
      cfg.AddNats(c => c.NatsOpts(opts => opts.Url = "nats://localhost:4222"));
})

Complete Example

Here's a complete configuration example combining all the essential parts:

using FxMap;
 
var builder = WebApplication.CreateBuilder(args);
 
// Add FxMap services
builder.Services.AddFxMap(cfg =>
{
    // Register entity configs from your assembly
    cfg.AddEntitiesFromAssemblyContaining<SomeEntityAssemblyMarker>();
 
    // Register DTO profiles from your assembly
    cfg.AddProfilesFromAssemblyContaining<SomeProfileAssemblyMarker>();
    cfg.AddRabbitMq(config =>
    {
        config.Host("localhost", "/", 5672, c =>
        {
            c.UserName("guest");
            c.Password("guest");
        });
    });
})
.AddEntityFrameworkCore(options => options.AddDbContexts(typeof(TestDbContext), typeof(OtherDbContext)...)});
 
var app = builder.Build();
 
app.Run();

Configuration Complete

Your FxMap configuration is now set up! The framework is ready to:

  • Discover EntityConfigureOf and ProfileOf classes from registered assemblies
  • Connect to your data source
  • Enable cross-service communication (if transport configured)
  • Automatically map data using your FluentAPI profiles

Version Compatibility

Remember: All FxMap packages (FxMap, FxMap.EntityFrameworkCore, FxMap.RabbitMq, etc.) must have the same version number to ensure compatibility.


Source: https://fxmapper.net/docs/basic-configuration/ — the website is always the most up to date version.

Clone this wiki locally