Skip to content

ProjectToType doesn't work with DI(MapContext) #266

Closed
@sonsy-soft

Description

@sonsy-soft

I have this Config

public void Register(TypeAdapterConfig config)
        {
            config
                .NewConfig<Domain.Entity.News.News, SitemapNode>()
                .AddDestinationTransform((string x) => x.Trim())
                .Map(dest => dest.Url,                   src => GetNewsUrl(src.Id,src.Title))
                .Map(dest => dest.LastModified,   src => src.ModifiedDate == null ? src.CreatedDate:src.ModifiedDate.Value)
              ;
        }

        private string GetNewsUrl(long ID, string TItle)
        {
            var HttpContextAccessor = MapContext.Current.GetService<IHttpContextAccessor>();
            return "Fine";          
        }

when I want to run the below code I got exception :

await
                  _Context
                   .Set<Domain.Entity.News.News>()
                    .AsNoTracking()
                    .ProjectToType<SitemapNode>(_mapper.Config)
                    .ToListAsync(cancellationToken)
                    .ConfigureAwait(false);

InvalidOperationException: Mapping must be called using ServiceAdapter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions