Open Closed

Injecting service into AutoMapper profile #472


User avatar
0
alexander.nikonov created
  • ABP Framework version: v3.2
  • UI type: Angular

We want to work with some service inside AutoMapper profile. Below is just the idea which does not work. Please suggest how to implement such DI:

        private void ConfigureAutoMapper(ServiceConfigurationContext context)
        {
            context.Services.AddSingleton(provider => new AutoMapper.MapperConfiguration(cfg =>
            {
                //TODO: implement
                cfg.AddProfile(new CentralToolsApplicationAutoMapperProfile
                (
                    provider.GetService<IBlobContainer<FileContainer>>()
                ));
            }).CreateMapper());
        }
        
        public class CentralToolsApplicationAutoMapperProfile : AutoMapper.Profile
        {
            //TODO: implement
            
            public CentralToolsApplicationAutoMapperProfile()
            {
                    CreateMap(...);
                    CreateMap(...);
            }
        }

public class MyCustomUserMapper : IObjectMapper<User, UserDto>, ITransientDependency approach seems not to be useful for our case.


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The use of DI in profile is not supported, please check https://github.com/abpframework/abp/issues/5288

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38