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 v8.2.0-preview Updated on March 25, 2024, 15:11