The high performance and easiest way to play with microservices for .NET
$ dotnet add package OfXpublic string XId { get; set; }
[XOf(nameof(XId))] public string X { get; set; }
OfX is an open-source library focused on Attribute-based data mapping. It streamlines data handling across services, reduces boilerplate code, and improves maintainability.
Full Documentation | Getting Started |Expression Language
[!WARNING] All OfX* packages need to have the same version.
dotnet add package OfX
// 1. Configure OfX
builder.Services.AddOfX(cfg =>
{
cfg.AddAttributesContainNamespaces(typeof(UserOfAttribute).Namespace!);
cfg.AddModelConfigurationsFromNamespaceContaining<SomeModelAssemblyMarker>();
});
// 2. Define a custom OfXAttribute
public sealed class UserOfAttribute(string propertyName) : OfXAttribute(propertyName);
// 3. Configure the model
[OfXConfigFor<UserOfAttribute>(nameof(Id), nameof(Name))]
public sealed class User
{
public string Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
// 4. Use attributes in your DTOs
public sealed class SomeDataResponse
{
public string UserId { get; set; }
[UserOf(nameof(UserId))]
public string UserName { get; set; }
[UserOf(nameof(UserId), Expression = "Email")]
public string UserEmail { get; set; }
}
// Simple property access
[UserOf(nameof(UserId), Expression = "Email")]
public string UserEmail { get; set; }
// Navigation properties
[ProvinceOf(nameof(ProvinceId), Expression = "Country.Name")]
public string CountryName { get; set; }
// Filtering
[UserOf(nameof(UserId), Expression = "Orders(Status = 'Done')")]
public List<OrderDTO> CompletedOrders { get; set; }
// Aggregation
[UserOf(nameof(UserId), Expression = "Orders:sum(Total)")]
public decimal TotalSpent { get; set; }
// Projection
[UserOf(nameof(UserId), Expression = "{Id, Name, Address.City as CityName}")]
public UserInfo UserDetails { get; set; }
// GroupBy
[UserOf(nameof(UserId), Expression = "Orders:groupBy(Status).{Status, :count as Count}")]
public List<OrderSummary> OrdersByStatus { get; set; }
For complete expression syntax including filters, indexers, functions, aggregations, boolean functions, coalesce, ternary operators, and more, visit Expression Documentation.
| Package | Description | .NET |
|---|---|---|
| Core | ||
| OfX | Core library | 8.0, 9.0 |
| Data Providers | ||
| OfX-EFCore | Entity Framework Core provider | 8.0, 9.0 |
| OfX-MongoDb | MongoDB provider | 8.0, 9.0 |
| Integrations | ||
| OfX-HotChocolate | HotChocolate GraphQL integration | 8.0, 9.0 |
| Transports | ||
| OfX-gRPC | gRPC transport | 8.0, 9.0 |
| OfX-Nats | NATS transport | 8.0, 9.0 |
| OfX-RabbitMq | RabbitMQ transport | 8.0, 9.0 |
| OfX-Kafka | Kafka transport | 8.0, 9.0 |
| OfX-Azure.ServiceBus | Azure Service Bus transport | 8.0, 9.0 |
Visit ofxmapper.net for:
Contributions are welcome! Please visit our GitHub repository to:
This project is licensed under the Apache-2.0 license.