I think the answer to this question is so obivous that noone has bothered writing about this, but its late and I really can't get my head around this.
I've been reading into IoC containers (Windsor in this case) and I'm missing how you talk to the container from the various parts of your code.
I get DI, I've been doing poor mans DI (empty constructors calling overloaded injection constructors with default parameter implementations) for some time and I can completely see the benefit of the container. However, Im missing one vital piece of info; how are you supposed to reference the container every time you need a service from it?
Do I create a single global insance which I pass around? Surely not!
I know I should call this:
WindsorContainer container = new WindsorContainer(new XmlInterpreter());
(for example) when I want to load my XML config, but then what do I do with container? Does creating a new container every time thereafter persist the loaded config through some internal static majicks or otherwise, or do I have to reload the config every time (i guess not, or lifecycles couldnt work).
Failing to understand this is preventing me from working out how the lifecycles work, and getting on with using some IoC awsomeness
Thanks,
Andrew
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…