예제 #1
0
        /// <summary>
        /// Builds all Mapster mappings and registers the mapper as a service.
        /// </summary>
        private void ConfigureMapsterServices(IServiceCollection services)
        {
            var config = new TypeAdapterConfig
            {
                RequireExplicitMapping = true,
            };

            foreach (var map in RuntimeHelper.GetAllInstances <IMapped>())
            {
                map.Configure(config);
            }

            config.Compile();
            var mapper = new Mapper(config);

            services.AddSingleton <IMapper>(mapper);
        }
예제 #2
0
        public static TypeAdapterConfig CreateMapper()
        {
            TypeAdapterConfig config = new TypeAdapterConfig()
            {
                Compiler = exp => exp.CompileWithDebugInfo(new ExpressionCompilationOptions {
                    ThrowOnFailedCompilation = true
                })
            };

            config.NewConfig <Kind, KindResponse>()
            .MaxDepth(1)
            .Map(dest => dest.KindId, src => src.Id)
            .TwoWays();

            config.NewConfig <AddKindRequest, Kind>()
            .MaxDepth(1)
            .Map(dest => dest.Name, src => src.KindName)
            .TwoWays();

            //config.NewConfig<Genre, GetGenreRequest>();

            config.NewConfig <Genre, GenreResponse>()
            .MaxDepth(1)
            .Map(dest => dest.GenreId, src => src.Id)
            .TwoWays();

            config.NewConfig <AddGenreRequest, Genre>()
            .MaxDepth(1)
            .Map(dest => dest.Name, src => src.GenreName)
            .TwoWays();

            //config.NewConfig<AddVideoRequest, Video>();

            //config.NewConfig<EditVideoRequest, Video>();

            config.NewConfig <Video, VideoResponse>()
            .MaxDepth(2)
            .TwoWays();

            config.Compile();

            return(config);
        }
예제 #3
0
        public static TypeAdapterConfig CreateMap()
        {
            TypeAdapterConfig config = new TypeAdapterConfig();

            config.NewConfig <Kind, KindResponse>()
            .MaxDepth(1)
            .Map(dest => dest.KindId, src => src.Id)
            .TwoWays();

            config.NewConfig <AddKindRequest, Kind>()
            .MaxDepth(1)
            .Map(dest => dest.Name, src => src.KindName)
            .TwoWays();

            //config.NewConfig<Genre, GetGenreRequest>();

            config.NewConfig <Genre, GenreResponse>()
            .MaxDepth(1)
            .Map(dest => dest.GenreId, src => src.Id)
            .TwoWays();

            config.NewConfig <AddGenreRequest, Genre>()
            .MaxDepth(1)
            .Map(dest => dest.Name, src => src.GenreName)
            .TwoWays();

            //config.NewConfig<AddVideoRequest, Video>();

            //config.NewConfig<EditVideoRequest, Video>();

            config.NewConfig <Video, VideoResponse>()
            .MaxDepth(2)
            .TwoWays();

            config.Compile();

            return(config);
        }