1: using System;
2: using Spring.Context.Support;
3: using Spring.Objects.Factory.Support;
4:
5: namespace SpringSeries.Core.ObjectDefinitionBuilderFluentInterface
6: {
7: class Program
8: {
9: static void Main(string[] args)
10: {
11: GenericApplicationContext _ctx = new GenericApplicationContext();
12:
13: _ctx.RegisterObjectDefinition("EngTranslator", ObjectDefinitionBuilder
14: .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(EnglishToItalianTranslator))
15: .SetSingleton(true)
16: .ObjectDefinition);
17:
18: _ctx.RegisterObjectDefinition("SpaTranslator", ObjectDefinitionBuilder
19: .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(SpanishToItalianTranslator))
20: .SetSingleton(true)
21: .ObjectDefinition);
22:
23: _ctx.RegisterObjectDefinition("ConsoleLog", ObjectDefinitionBuilder
24: .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(ConsoleTranslatorLog))
25: .SetSingleton(true)
26: .ObjectDefinition);
27:
28:
29: _ctx.RegisterObjectDefinition("Translator", ObjectDefinitionBuilder
30: .RootObjectDefinition(new DefaultObjectDefinitionFactory(), typeof(PhraseTranslator))
31: .AddConstructorArgReference("EngTranslator")
32: .AddPropertyReference("Log","ConsoleLog")
33: .SetSingleton(true)
34: .ObjectDefinition);
35:
36: PhraseTranslator _translator = (PhraseTranslator)_ctx.GetObject("Translator");
37: Console.WriteLine(_translator.Translate("Hello Spring.NET !!"));
38: Console.WriteLine(_translator.Translate("Hola Spring.NET !!"));
39: Console.Read();
40: }
41: }
42: }