我按如下方式配置了装饰器
Bind<IEmailService>().To<EmailService>().WhenInjectedInto<LoggerEmailService>();
Bind<IEmailService>().To<LoggerEmailService>().WhenInjectedInto<ExceptionHandlerEmailService>();
Bind<IEmailService>().To<ExceptionHandlerEmailService>();
当我在服务实现的ctor中放置一个断点时,比如ExceptionHandlerEmailService或者只是EmailService,我发现该服务被多次调用。我错过了什么?
答案 0 :(得分:0)
.InSingletonScope()就是所需要的。
Bind<IEmailService>().To<ExceptionHandlerEmailService>().InSingletonScope();
Bind<IEmailService>().To<LoggerEmailService>().WhenInjectedInto<ExceptionHandlerEmailService>();
Bind<IEmailService>().To<EmailService>().WhenInjectedInto<LoggerEmailService>();