How luckypennysoftware/automapper works
Project Type and Purpose
• AutoMapper is an open-source .NET library (distributed via NuGet) whose sole purpose is to automate the mapping of properties from one object type to another, eliminating boilerplate code.
• It provides a core mapping engine, extension packages, DI integration, expression‐tree based projection, and extensive test/benchmark suites.
File Structure Analysis
• src/AutoMapper: the core library project, containing Configuration, Execution, Mappers, QueryableExtensions, Internal, Licensing, and public entry points (MapperConfiguration, Mapper, IMapper).
• src/AutoMapper.DI.Tests, src/IntegrationTests, src/UnitTests: test projects validating different integration points (DI containers, EF Core mapping, advanced scenarios) and core mapping behavior.
• src/Benchmark: benchmarks comparing different mapping approaches.
• src/TestApp: a sample console app to demonstrate usage.
• docs: Sphinx/ReadTheDocs sources for user documentation.
• GitHub workflows (.github/workflows): CI, release, lockfile maintenance.
• Build scripts (Build.ps1, Setup.ps1, Push.ps1) and solution-wide props/configs (.sln, Directory.Build.props, nuget.config).
Key README Insights
• Core concept: configure type maps (cfg.CreateMap<TSource,TDest>()), then resolve at runtime via IMapper.Map<T> or LINQ projections.
• Supports dependency‐injection registration, mapping configuration validation, license key management.
• Mentions related extension repositories.
a. Main Components
• Core Mapping Engine (src/AutoMapper)
• Configuration API (MapperConfiguration + Profiles)
• Mapping Pipeline (IObjectMapper implementations, Convention system, ExpressionBuilder, TypeMapPlanBuilder)
• DI Integration Layer (ServiceCollectionExtensions + AutoMapper.DI.Tests)
• Queryable Extensions (LINQ projection translator)
• Extension Points (Custom Type Converters, Value Resolvers, Conventions)
• External Dependencies: .NET Runtime, Dependency‐Injection Container(s)
• Support Modules: Benchmarking, Test Projects, Documentation site
• Build & Release Pipeline (GitHub Actions, PowerShell scripts)
b. Relationships & Data Flows
• On startup, user code invokes MapperConfiguration → Profiles → builds internal TypeMap graph.
• When Map<TSource,TDest>() is called, the Mapping Pipeline uses ObjectFactory and ExpressionBuilder to generate and cache a delegate or expression tree.
• For IQueryable<T> projection, QueryableExtensions rewrites expression trees from source to destination.
• DI Extension registers MapperConfiguration and IMapper in IServiceCollection to resolve via constructor injection.
• Tests and Benchmarks invoke the public API to validate and measure performance; they depend on the core library assembly.
• Build scripts orchestrate compilation, tests, packaging to NuGet, and publishing via GitHub Actions.
c. Architectural Patterns & Principles
• Pipeline Pattern: IObjectMapper chain for different mapping strategies.
• Convention over Configuration: default member and type matching conventions, override via explicit Profiles.
• Factory Pattern: ObjectFactory for instance creation, ProxyGenerator for dynamic types.
• Dependency Injection: extension methods and tests demonstrating service registration.
• Expression Tree Manipulation: ProjectionBuilder, NullsafeQueryRewriter.
• Modularity: separation of core, DI, projection, tests, benchmarks, documentation.
d. Technologies & Frameworks
• C#/.NET (Core + Framework compatibility)
• Roslyn/expression‐tree API
• GitHub Actions for CI/CD
• Sphinx/ReadTheDocs for documentation
• NuGet packaging
Details to Capture
• Layered arrangement: Public API at top, internal pipeline components in the middle, infrastructure (ReflectionHelper, Licensing) at bottom.
• Configuration flow (Profiles → TypeMapConfiguration → MemberConfigurationExpression).
• Build & release process separately, showing source repos → GitHub Actions → NuGet.org.