On 6/26/06, Michael Youngstrom <yo...@gm...> wrote:
>
> By "injecting a static field" are you saying injecting the singleton
> into a class variable? Though I cannot seem to put my finger on
> exactly why....right off hand something about that idea doesn't seem
> right.
Unit testing classes with static state is more difficult than those with
purely instance state because you have to explicitly clean up the state in a
tearDown() method or else risk impacting another test. But, in this case,
injecting statics is a lot simpler than employing AOP proxies and cleaner
than requiring a static reference to your container (so you can re-inject
values upon deserialization).
If you want to do that why not just create a "setSingletonInstance"
> non static method that sets your static "SingletonInstance" class
> variable? Though there would be the security concern of providing
> access to a non final class variable.
>
Yuck. That's confusing, the property will be unnecesarily re-injected every
time you instantiate an instance of that type, and now your static field has
to be volatile (due to concurrent reads and writes).
Bob
|