jeudi 2 janvier 2020

When is it appropriate to use @Singleton and @Prototype in Micronauts?

I read so many bad things about singleton pattern (What is so bad about singletons?), however, @Singleton is used everywhere in this Micronaut doc to illustrate inversion of control https://docs.micronaut.io/1.3.0.M2/guide/index.html#ioc

When is it appropriate to use @Singleton? For example, if I have a UserInfoService that has getUserInfo, createUserInfo, updateUserInfo method, is it a good idea to use @Singleton?

Another separate question is when do I use @Prototype, because if I don't use any annotation for a function/class, isn't it by default a prototype (as in I initiate a new instance of it in another class/function)?

Aucun commentaire:

Enregistrer un commentaire