Skip to content

Does this work with AutoMapper.Extensions.Microsoft.DependencyInjection? #2

Closed
@ChristopherHaws

Description

@ChristopherHaws

Hi Jimmy,

Is there a way to setup the GenerateEntityFrameworkCorePrimaryKeyPropertyMaps when using AutoMapper.Extensions.Microsoft.DependencyInjection? From what I can see, GenerateEntityFrameworkCorePrimaryKeyPropertyMaps needs an IServiceProvider, which is not available in ConfigureServices without registering the service using the implementation factory overload of one of the Add calls on IServiceCollection.

Ideally, I would like to be able to do something along the lines of:

services.AddAutoMapper(mapper =>
{
	mapper.AddCollectionMappers();
	mapper.SetGeneratePropertyMaps<GenerateEntityFrameworkCorePrimaryKeyPropertyMaps<MyContext>>();
});

but there appears to be a chicken and egg problem here. From what I can tell, SetGeneratePropertyMaps immediately creates an instance of the property map generator and attempts to build the mappings rather than doing it after the container has been built or when IMapper is resolved.

Thanks! :)

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