This project provides a dynamic mapper system to handle bidirectional data mapping between internal DIRS21
C# data models and external partner-specific data models. The solution is built using ASP.NET Core and follows the Onion architecture, ensuring scalability, maintainability, and separation of concerns. It provides a highly dynamic approach to adding new mappings with minimal modifications to the existing codebase. Leveraging the concept of dynamic C# execution, it offers comprehensive flexibility to validate, update, modify, and enhance mappings as needed.
-
Dynamic Mapping:
- Map data between internal and partner formats.
- Store and execute dynamic C# code for mapping.
-
Caching and Database Integration:
- Uses
MemoryCache
for fast retrieval of mappings. - Integrates
LiteDB
for persistent storage of mappings.
- Uses
-
Environment Support:
- Supports
Development
andProduction
environments usingappsettings.Development.json
andappsettings.Production.json
.
- Supports
-
Testing Framework:
- Includes unit tests in a dedicated test project (
Tests
) for validating functionality.
- Includes unit tests in a dedicated test project (
-
Developer Experience:
- Offers a Swagger UI for manual testing and exploration.
- Provides clear and simple API endpoints.
The solution is designed using Onion architecture:
-
API Project:
- Entry point (
Program.cs
) handles service registration and application startup. - Contains the
MappingsController
with three main endpoints:- Get Mapping: Retrieve existing mappings.
- Save Mapping: Store source type, target type, and dynamic mapping code.
- Map Data: Perform mapping using stored C# code.
- Entry point (
-
Application Project:
- Houses business logic in the
MappingService
. - Manages interactions with the cache and database.
- Houses business logic in the
-
Domain Project:
- Defines core entities and interfaces.
-
Infrastructure Project:
- Handles external concerns such as database integration with
LiteDB
.
- Handles external concerns such as database integration with
-
Application Startup:
- The app starts in
Program.cs
, where services are registered and initialized. - Swagger UI is launched for testing endpoints.
- The app starts in
-
Workflow:
- Requests are handled by
MappingsController
, which delegates logic toMappingService
. MappingService
:- Retrieves mappings from
MemoryCache
orLiteDB
. - Executes dynamic C# mapping code stored in the database.
- Retrieves mappings from
- Requests are handled by
-
Endpoints:
- GET /Mappings/{key}: Retrieve an existing mapping by key (e.g. Reservation), source type, and target type.
- PUT /Mappings/{key}: Save a key, source type, target type, and dynamic mapping code.
- POST /Mappings/{key}/MapData: Map a source data object to a target type using stored dynamic code.
- The project includes a
Tests
project with example unit tests (not a 100% coverage):- Validates saving and retrieving mappings.
- Ensures correct execution of dynamic mapping logic.
-
Prerequisites:
- .NET 8 SDK or later.
- An IDE like Visual Studio for ASP.NET Core development.
-
Running the Application:
- Clone the repository and build the solution.
- Run the project to start the API server.
- Use Swagger UI for manual API interaction or
MainTests.cs
for automated and ready use-case testing.
-
Endpoints:
- Access Swagger UI for testing API endpoints.
- Refer to
MainTests.cs
for example inputs and test cases.
-
Advanced Caching:
- Replace
MemoryCache
with distributed caching (e.g., Redis) for scalability.
- Replace
-
Database Optimization:
- Upgrade
LiteDB
to a robust solution like SQL Server or MongoDB for production.
- Upgrade
-
Enhanced Testing:
- Add integration tests and use mocking frameworks.
- Include performance benchmarks for mapping operations.
This project demonstrates a maintainable, scalable solution for dynamic data mapping. It adheres to software engineering best practices while allowing room for future growth and optimization.