Skip to content

Instantly share code, notes, and snippets.

@ismkdc
Last active September 5, 2023 08:13
Show Gist options
  • Save ismkdc/3991e816975f2149b0f4d10eb7ad8227 to your computer and use it in GitHub Desktop.
Save ismkdc/3991e816975f2149b0f4d10eb7ad8227 to your computer and use it in GitHub Desktop.
using System.Linq;
using FastExpressionCompiler;
using Mapster;
namespace foobar;
public static class MappingConfiguration
{
public static TypeAdapterConfig Generate()
{
var config = new TypeAdapterConfig();
config.NewConfig<foo, bar>()
.Map(dest => dest.Color,
src => src.Category.Color)
.Map(dest => dest.CategorySlug,
src => src.Category.Slug)
.Ignore(dest => dest.Reactions);
config.NewConfig<lol, asd>();
config.Compiler = exp => exp.CompileFast();
config.Compile();
return config;
}
}
### ON STARTUP ###
//register mapster
var config = MappingConfiguration.Generate();
services.AddSingleton(config);
services.AddSingleton<IMapper, ServiceMapper>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment