On Sun, Mar 21, 2010 at 6:06 PM, Richtermeister <[email protected]> wrote: > I keep seeing the example of the mailer as a dependency of an action, > but in reality, aren't dependencies often conditional? > For example, sending a mail often depends on whether, say, a form > validates. By passing the mailer into the constructor or the method > directly, we would "always" instantiate it, even though it's only > "sometimes" needed. > Having read about the DI container, I was under the impression that > it's lazy loading abilities were supposed to fix just that problem, > that the mailer is only instantiated when I really (!) need it, not > "potentially" need it.
This is only true if you pass the entire container, then when you do $container->mailer, it instantiates it. If you pass it as a parameter directly, no matter how, it is indeed instantiated always. As I previously said, in most cases, the code sending a mail isn't going to be executed that much that it actually matters, but in some cases it might. In those cases though, you could always ask for the $container service itself as a parameter, and fetch the mailer from it only when really needed. Cheers, Jordi -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-devs?hl=en To unsubscribe from this group, send email to symfony-devs+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
