Re: Is it possible to inject Spring service into a Selma custom mapper ?

367 views
Skip to first unread message

Séven Le Mesle

unread,
Feb 22, 2017, 5:59:14 PM2/22/17
to tehb...@gmail.com, Selma
Hi,

the SelmaCustomMapper should be a Spring @Service so you can inject everything you want into it.

Tell me if that helps.


2017-02-22 22:01 GMT+01:00 <tehb...@gmail.com>:
Actually I see the documentation says: Every custom mapper instance can be injected in the generated class when you build it from Selma. This allows custom mappers to use some services of your application code.
But there are no exemple in the sample project. 


On Wednesday, February 22, 2017 at 9:39:52 PM UTC+1, tehb...@gmail.com wrote:
Hey there,

I've 2 beans

public class PersonDTO { private String name; private String compagnyName; }

public class Person { private String name; private String compagnyKey; }

My regular factory code would be

@Service
public class PersonFactory {

@Autowired private IConfigurationService conf;

public PersonDto convertPersonToPersonDto(Person origine) {
  PersonDTO result = new PersonDTO();
  result.setName(origine.getName();
  result.setCompagny(conf.findCompagnyName(origine.getCompagnyKey));
}
}


So I created a SelmaMapper

@Mapper(withIgnoreFields = "compagnyName", withCustom = SelmaCustomMapper.class, withIoC = IoC.SPRING) public interface SelmaMapper {
PersonDto asPersonDto(Person source);
}

But is there a way to get the IConfigurationService conf injected into SelmaCustomMapper?

--
You received this message because you are subscribed to the Google Groups "Selma" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selma-java+unsubscribe@googlegroups.com.
To post to this group, send email to selma...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selma-java/bfc7f57d-2d92-4262-ad41-3fa93596d223%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Séven Le Mesle 

Xebia logo
« Software Development Done Right »
156, boulevard Haussmann, 75008 Paris 
+33(0)6 19  61 81 17slem...@xebia.fr
Great Place To Work 2014
Alliance logo
Reply all
Reply to author
Forward
0 new messages