Giter VIP home page Giter VIP logo

batmap's Introduction

BatMap - The Mapper we deserve, not the one we need.

Opininated (yet another) mapper, mainly to convert between EF Entities and DTOs.

Build Status Coverage Status

Let's first obey the number one rule for mappers, a benchmark (using BenchmarkDotNet):

Method Mean
BatMap 💥 1.8563 ms 💥
Mapster 2.0414 ms
SafeMapper 2.0589 ms
HandWritten 2.1000 ms
AutoMapper 2.7422 ms
TinyMapper 2.8609 ms
ExpressMapper 4.9961 ms
FastMapper 5.7874 ms

Results may (probably) vary

  • Fast (enough)
  • NOT over-engineered, code is really simple
  • Instantiatable mapper
  • Convention based, zero configuration static shortcut exists too (obviously named Mapper)
  • Does not crash when faced with circular-dependencies during registration
  • In fact, can resolve recurring instances to same target instance (yaay no StackOverflowException!)
  • Can project IQueryable<TSource> to IQueryable<TTarget> with respect to includes (via auto-detection or with custom parameters)
  • and much more...

API

Registration with static API:

Mapper.RegisterMap<Customer, CustomerDTO>();

or use an instance:

var mapper = new MapConfiguration(dynamicMapping: DynamicMapping.MapAndCache, preserveReferences: true);
mapper.RegisterMap<Customer, CustomerDTO>();

Note: You don't have to register type mappings when using a MapConfiguration with Dynamic Mapping enabled (like the static API uses).

You can customize expressions for members:

mapper.RegisterMap<Order, OrderDTO>(b => b.MapMember(o => o.Price, (o, mc) => o.Count * o.UnitPrice));

Map an object:

Mapper.Map<CustomerDTO>(customer);

Map an enumerable:

customers.Map<Customer, CustomerDTO>(preserveReferences: true);  // extension methods FTW!

Project a query:

customerQuery.ProjectTo<CustomerDTO>(checkIncludes: true);

or with expanding specific navigations:

customerQuery.ProjectTo<Customer, CustomerDTO>(c => c.Addresses, c => c.Orders);

Note: If you want to change mapping behavior, create a class that inherits from ExpressionProvider, override CreateMemberBinding and inject an instance of your class to MapConfiguration.

Developed with ❤️ at Doğuş Teknoloji.

batmap's People

Contributors

umutozel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.