public void ClearWithDynamicProxies()
        {
            CompositionProxyTypeBuilder typeBuilder = new CompositionProxyTypeBuilder();
            typeBuilder.TargetType = typeof(TestObject);
            Type proxyType = typeBuilder.BuildProxyType();

            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            RootObjectDefinition od1 = new RootObjectDefinition(proxyType, false);
            od1.PropertyValues.Add("Name", "Bruno");
            of.RegisterObjectDefinition("testObject", od1);

            GenericApplicationContext ctx1 = new GenericApplicationContext(of);
            ContextRegistry.RegisterContext(ctx1);

            ITestObject to1 = ContextRegistry.GetContext().GetObject("testObject") as ITestObject;
            Assert.IsNotNull(to1);
            Assert.AreEqual("Bruno", to1.Name);

            DefaultListableObjectFactory of2 = new DefaultListableObjectFactory();
            RootObjectDefinition od2 = new RootObjectDefinition(proxyType, false);
            od2.PropertyValues.Add("Name", "Baia");
            of2.RegisterObjectDefinition("testObject", od2);
            GenericApplicationContext ctx2 = new GenericApplicationContext(of2);

            ContextRegistry.Clear();

            ITestObject to2 = ctx2.GetObject("testObject") as ITestObject;
            Assert.IsNotNull(to2);
            Assert.AreEqual("Baia", to2.Name);
        }
Beispiel #2
0
    static async Task AsyncMain()
    {
        Console.Title = "Samples.Spring";
        #region ContainerConfiguration
        EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Samples.Spring");
        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
        endpointConfiguration.UseContainer<SpringBuilder>(c => c.ExistingApplicationContext(applicationContext));
        #endregion
        endpointConfiguration.UseSerialization<JsonSerializer>();
        endpointConfiguration.UsePersistence<InMemoryPersistence>();

        endpointConfiguration.SendFailedMessagesTo("error");

        IEndpointInstance endpoint = await Endpoint.Start(endpointConfiguration);
        try
        {
            await endpoint.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpoint.Stop();
        }
    }
        public void SetUp()
        {
            context = new GenericApplicationContext();

            cacheAspect = new CacheAspect();
            cacheAspect.ApplicationContext = context;
        }
Beispiel #4
0
        public static object createTypeSetPropertiesAndInvokeMethod(Type tTargetType, String sMethodToInvoke,
                                                                    Dictionary<String, Object> dProperties)
        {
            string sFactoryObject = "FactoryObject";
            string sInvokeResult = "InvokeResult";
            var ctx = new GenericApplicationContext();

            // create factory Object,  add (if required) its properties to it and register it
            var rodFactoryObject = new RootObjectDefinition {ObjectType = tTargetType};
            if (dProperties != null)
                foreach (String sProperty in dProperties.Keys)
                    rodFactoryObject.PropertyValues.Add(sProperty, dProperties[sProperty]);

            ctx.RegisterObjectDefinition(sFactoryObject, rodFactoryObject);

            // create object to invoke method and register it

            var rodMethodToInvoke = new RootObjectDefinition
                                        {
                                            FactoryMethodName = sMethodToInvoke,
                                            FactoryObjectName = sFactoryObject
                                        };

            ctx.RegisterObjectDefinition(sInvokeResult, rodMethodToInvoke);

            // when we get the rodMethodToInvoke object, the rodFactoryObject will be created
            return ctx.GetObject(sInvokeResult);
        }
Beispiel #5
0
        public void GenericApplicationContextConstructorTests()
        {
            IApplicationContext       ctx        = new XmlApplicationContext("assembly://Spring.Core.Tests/Spring.Context/contextlifecycle.xml");
            GenericApplicationContext genericCtx = new GenericApplicationContext(ctx);

            genericCtx = new GenericApplicationContext("test", true, ctx);
        }
        public void Setup()
        {
            _applicationContext = new GenericApplicationContext();

            var objDef = new RootObjectDefinition(typeof (InitDestroyAttributeObjectPostProcessor));
            objDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
            _applicationContext.ObjectFactory.RegisterObjectDefinition("InitDestroyAttributeObjectPostProcessor", objDef);

            objDef = new RootObjectDefinition(typeof(PostContructTestObject1));
            _applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject1", objDef);

            objDef = new RootObjectDefinition(typeof(PostContructTestObject2));
            _applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject2", objDef);
            
            objDef = new RootObjectDefinition(typeof(PostContructTestObject3));
            _applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject3", objDef);

            objDef = new RootObjectDefinition(typeof(PostContructTestObject4));
            objDef.Scope = "prototype";
            _applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject4", objDef);

            objDef = new RootObjectDefinition(typeof(PostContructTestObject5));
            _applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject5", objDef);

            objDef = new RootObjectDefinition(typeof(PostContructTestObject1));
            objDef.InitMethodName = "Init1";
            _applicationContext.ObjectFactory.RegisterObjectDefinition("PostContructTestObject6", objDef);

            _applicationContext.Refresh();
        }
        public void CanProxyFactoryMethodProducts()
        {
            GenericApplicationContext ctx = new GenericApplicationContext();
            ctx.ObjectFactory.AddObjectPostProcessor(new DefaultAdvisorAutoProxyCreator());

            CapturingAdvice capturingAdvice = new CapturingAdvice();
            ctx.ObjectFactory.RegisterSingleton("logging", new DefaultPointcutAdvisor(TruePointcut.True, capturingAdvice));

            // register "factory" object 
            RootObjectDefinition rod;
            rod = new RootObjectDefinition(typeof(TestObjectFactoryObject));
            ctx.ObjectFactory.RegisterObjectDefinition("test", rod);

            // register product, referencing the factory object
            rod = new RootObjectDefinition(typeof(ITestObject));
            rod.FactoryObjectName = "test";
            rod.FactoryMethodName = "CreateTestObject";
            ctx.ObjectFactory.RegisterObjectDefinition("testProduct", rod);

            ctx.Refresh();

            ITestObjectFactoryObject fo = (ITestObjectFactoryObject) ctx.GetObject("test");
            Assert.IsTrue( AopUtils.IsAopProxy(fo) );
            Assert.AreEqual("CreateTestObject", ((IMethodInvocation)capturingAdvice.CapturedCalls[0]).Method.Name);

            capturingAdvice.CapturedCalls.Clear();
            ITestObject to = (ITestObject)ctx.GetObject("testProduct");
            Assert.IsTrue( AopUtils.IsAopProxy(to) );
            Assert.AreEqual("TheName", to.Name);
            Assert.AreEqual("get_Name", ((IMethodInvocation)capturingAdvice.CapturedCalls[0]).Method.Name);
        }
Beispiel #8
0
    static void Main()
    {
        Console.Title = "Samples.Spring";
        Configure.Serialization.Json();
        #region ContainerConfiguration
        Configure configure = Configure.With();
        configure.Log4Net();
        configure.DefineEndpointName("Samples.Spring");
        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
        configure.SpringFrameworkBuilder(applicationContext);
        #endregion
        configure.InMemorySagaPersister();
        configure.UseInMemoryTimeoutPersister();
        configure.InMemorySubscriptionStorage();
        configure.UseTransport<Msmq>();
        using (IStartableBus startableBus = configure.UnicastBus().CreateBus())
        {
            IBus bus = startableBus.Start(() => configure.ForInstallationOn<Windows>().Install());
            bus.SendLocal(new MyMessage());

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }

    }
        /// <summary>
        /// Scans for types using the provided scanner.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="scanner">The scanner.</param>
        public static void Scan(this GenericApplicationContext context, AssemblyObjectDefinitionScanner scanner)
        {
            var registry = context.ObjectFactory as IObjectDefinitionRegistry;

            scanner.ScanAndRegisterTypes(registry);

            AttributeConfigUtils.RegisterAttributeConfigProcessors(registry);
        }
        protected override IServiceLocator CreateServiceLocator()
        {
            var context = new GenericApplicationContext(false);

            context.ObjectFactory.RegisterSingleton(typeof(SimpleLogger).FullName, new SimpleLogger());
            context.ObjectFactory.RegisterSingleton(typeof(AdvancedLogger).FullName, new AdvancedLogger());

            return new SpringAdapter(context);
        }
Beispiel #11
0
        void Existing(Configure configure)
        {
            #region Spring_Existing

            GenericApplicationContext applicationContext = new GenericApplicationContext();
            applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
            configure.SpringFrameworkBuilder(applicationContext);
            #endregion
        }
 public void SetUp()
 {
     string physDir = AppDomain.CurrentDomain.BaseDirectory + "\\";
     IApplicationContext appContext =
         new XmlApplicationContext(AbstractApplicationContext.DefaultRootContextName, false, RES_OBJECTS);
     ContextRegistry.RegisterContext(appContext);
     appContext = new GenericApplicationContext("/controls/", false, appContext);
     ContextRegistry.RegisterContext(appContext);
 }
Beispiel #13
0
        public SpringContainer(GenericApplicationContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            _context = context;
            _componentDefinitions = new Dictionary<Type, ComponentConfig>();
            _callModels = new Dictionary<Type, ComponentCallModelEnum>();
            _factory = new DefaultObjectDefinitionFactory();
        }
    void Existing(EndpointConfiguration endpointConfiguration)
    {
        #region Spring_Existing

        var applicationContext = new GenericApplicationContext();
        applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
        endpointConfiguration.UseContainer<SpringBuilder>(c => c.ExistingApplicationContext(applicationContext));

        #endregion
    }
        protected override void CreateApplicationContext()
        {
            GenericApplicationContext ctx = new GenericApplicationContext();

            ctx.ScanAllAssemblies();

            ctx.Refresh();

            _ctx = ctx;
        }
 public void TestNoFailOnStartupWithMissingBroker()
 {
     var connectionFactory = new SingleConnectionFactory("foo");
     connectionFactory.Port = 434343;
     var applicationContext = new GenericApplicationContext();
     applicationContext.ObjectFactory.RegisterSingleton("foo", new Queue("queue"));
     var rabbitAdmin = new RabbitAdmin(connectionFactory);
     rabbitAdmin.ApplicationContext = applicationContext;
     rabbitAdmin.AutoStartup = true;
     rabbitAdmin.AfterPropertiesSet();
 }
        public void Existing()
        {

            #region Spring_Existing

            BusConfiguration busConfiguration = new BusConfiguration();
            GenericApplicationContext applicationContext = new GenericApplicationContext();
            applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
            busConfiguration.UseContainer<SpringBuilder>(c => c.ExistingApplicationContext(applicationContext));

            #endregion
        }
        /// <summary>
        /// Scans for types that satisfy specified predicates located in the specified scan path.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="assemblyScanPath">The assembly scan path.</param>
        /// <param name="assemblyPredicate">The assembly predicate.</param>
        /// <param name="typePredicate">The type predicate.</param>
        public static void Scan(this GenericApplicationContext context, string assemblyScanPath, Predicate <Assembly> assemblyPredicate,
                                Predicate <Type> typePredicate)
        {
            //create a scanner instance using the scan path
            var scanner = new AssemblyObjectDefinitionScanner();

            //configure the scanner per the provided constraints
            scanner.WithAssemblyFilter(assemblyPredicate).WithIncludeFilter(typePredicate);

            //pass the scanner to primary Scan method to actually do the work
            Scan(context, scanner);
        }
        public void LookupRegisteredChannel()
        {
            GenericApplicationContext context = new GenericApplicationContext();
            QueueChannel testChannel = new QueueChannel();
            testChannel.ObjectName = "testChannel";
            context.ObjectFactory.RegisterSingleton("testChannel", testChannel);

            ObjectFactoryChannelResolver resolver = new ObjectFactoryChannelResolver(context);
            IMessageChannel lookedUpChannel = resolver.ResolveChannelName("testChannel");
            Assert.IsNotNull(testChannel);
            Assert.That(lookedUpChannel, Is.SameAs(testChannel));
        }
        public void Init()
        {
            this.context = new GenericApplicationContext();
            this.rabbitAdmin = new RabbitAdmin(this.connectionFactory);

            this.rabbitAdmin.DeleteQueue("test.queue");

            // Force connection factory to forget that it has been used to delete the queue
            this.connectionFactory.Dispose();
            this.rabbitAdmin.ApplicationContext = this.context;
            this.rabbitAdmin.AutoStartup = true;
        }
        public void Setup()
        {
            _context = new GenericApplicationContext();

            var objectDefinition = new RootObjectDefinition(typeof(DestructionPostProcessor));
            objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
            _context.ObjectFactory.RegisterObjectDefinition("DestructionPostProcessor", objectDefinition);

            var objectDef = new RootObjectDefinition(typeof(DestroyTester));
            _context.ObjectFactory.RegisterObjectDefinition("DestroyTester", objectDef);

            _context.Refresh();
        }
        /// <summary>
        /// Scans the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="assemblyScanPath">The assembly scan path.</param>
        /// <param name="assemblyPredicate">The assembly predicate.</param>
        /// <param name="typePredicate">The type predicate.</param>
        /// <param name="assembliesToScan">The assemblies to scan.</param>
        public static void Scan(this GenericApplicationContext context, string assemblyScanPath, Func <Assembly, bool> assemblyPredicate, Func <Type, bool> typePredicate, params string[] assembliesToScan)
        {
            AssemblyObjectDefinitionScanner scanner =
                ArrayUtils.HasElements(assembliesToScan) ? new AssemblyObjectDefinitionScanner(assembliesToScan) : new AssemblyObjectDefinitionScanner();

            scanner.ScanStartFolderPath = assemblyScanPath;

            //configure the scanner per the provided constraints
            scanner.WithAssemblyFilter(assemblyPredicate).WithIncludeFilter(typePredicate);

            //pass the scanner to primary Scan method to actually do the work
            Scan(context, scanner);
        }
        public void should_return_registered_context_with_ContextRegistry()
        {
			const string xmlData =
				@"<context type='Spring.Context.Support.XmlApplicationContext, Spring.Core'>
	                <resource uri='assembly://Spring.Web.Tests/Spring.Context.Support/WebContextHandlerTests.xml'/>
                 </context>";
            GenericApplicationContext expectedContext = new GenericApplicationContext(null, false, null);
            ContextRegistry.RegisterContext(expectedContext);
            WebContextHandler webContextHandler = new WebContextHandler();
            
            Object actualContext = webContextHandler.Create(null, null, CreateConfigurationElement(xmlData));

            Assert.AreSame(expectedContext, actualContext);
        }
 public void FailsWithNoPersistenceExceptionTranslators()
 {
     GenericApplicationContext gac = new GenericApplicationContext();
     gac.RegisterObjectDefinition("translator", new RootObjectDefinition(typeof(PersistenceExceptionTranslationPostProcessor)));
     gac.RegisterObjectDefinition("proxied", new RootObjectDefinition(typeof(StereotypedRepositoryInterfaceImpl)));
     try
     {
         gac.Refresh();
         Assert.Fail("Should fail with no translators");
     } catch (ObjectsException)
     {
         // expected.
     }
 }
        public void RegisterITypeName()
        {
            // Arrange
            var context = new GenericApplicationContext();
            context.Configure()
                .IncludeAssembly(x => x.FullName.StartsWith("Spring.AutoRegistration.Test"))
                .Include(x => x.ImplementsITypeName(), Then.Register())
                .ApplyAutoRegistration();

            // Act
            var foo = context.GetObject("Foo") as IFoo;

            // Assert
            foo.Should().NotBeNull();
        }
        public void RegisterPropertiesByName()
        {
            // Arrange
            var context = new GenericApplicationContext();
            context.Configure()
                .IncludeAssembly(x => x.FullName.StartsWith("Spring.AutoRegistration.Test"))
                .Include(x => x.ImplementsITypeName(), Then.Register().UsingSingleton().InjectByProperty(If.DecoratedWith<InjectAttribute>))
                .ApplyAutoRegistration();

            // Act
            var bar = context.GetObject("Bar") as Bar;

            // Assert
            bar.Foo.Should().NotBeNull();
        }
Beispiel #27
0
        public void GenericApplicationContextWithXmlObjectDefinitions()
        {
            GenericApplicationContext ctx    = new GenericApplicationContext();
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(ctx);

            reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextB.xml");
            reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextC.xml");
            reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextA.xml");
            ctx.Refresh();

            Assert.IsTrue(ctx.ContainsObject("service"));
            Assert.IsTrue(ctx.ContainsObject("logicOne"));
            Assert.IsTrue(ctx.ContainsObject("logicTwo"));
            ctx.Dispose();
        }
Beispiel #28
0
        public void should_return_registered_context_with_ContextRegistry()
        {
            const string xmlData =
                @"<context type='Spring.Context.Support.XmlApplicationContext, Spring.Core'>
	                <resource uri='assembly://Spring.Web.Tests/Spring.Context.Support/WebContextHandlerTests.xml'/>
                 </context>";
            GenericApplicationContext expectedContext = new GenericApplicationContext(null, false, null);

            ContextRegistry.RegisterContext(expectedContext);
            WebContextHandler webContextHandler = new WebContextHandler();

            Object actualContext = webContextHandler.Create(null, null, CreateConfigurationElement(xmlData));

            Assert.AreSame(expectedContext, actualContext);
        }
        protected override void CreateApplicationContext()
        {
            GenericApplicationContext ctx = new GenericApplicationContext();

            var configDefinitionBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(TheConfigurationClass));
            ctx.RegisterObjectDefinition(configDefinitionBuilder.ObjectDefinition.ObjectTypeName, configDefinitionBuilder.ObjectDefinition);

            var postProcessorDefintionBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(ConfigurationClassPostProcessor));
            ctx.RegisterObjectDefinition(postProcessorDefintionBuilder.ObjectDefinition.ObjectTypeName, postProcessorDefintionBuilder.ObjectDefinition);

            Assert.That(ctx.ObjectDefinitionCount, Is.EqualTo(2));

            ctx.Refresh();

            _ctx = ctx;
        }
        public void ProxiesCorrectly()
        {
            GenericApplicationContext gac = new GenericApplicationContext();
            gac.RegisterObjectDefinition("translator", new RootObjectDefinition(typeof(PersistenceExceptionTranslationPostProcessor)));
            gac.RegisterObjectDefinition("notProxied", new RootObjectDefinition(typeof(RepositoryInterfaceImpl)));
            gac.RegisterObjectDefinition("proxied",
                                         new RootObjectDefinition(typeof (StereotypedRepositoryInterfaceImpl)));            
            gac.RegisterObjectDefinition("chainedTranslator",
                                         new RootObjectDefinition(typeof (ChainedPersistenceExceptionTranslator)));
            gac.Refresh();
            
            IRepositoryInterface shouldNotBeProxied = (IRepositoryInterface) gac.GetObject("notProxied");
            Assert.IsFalse(AopUtils.IsAopProxy(shouldNotBeProxied));

            IRepositoryInterface shouldBeProxied = (IRepositoryInterface) gac.GetObject("proxied");
            Assert.IsTrue(AopUtils.IsAopProxy(shouldBeProxied));

            CheckWillTranslateExceptions(shouldBeProxied);

        }
        public void TestFailOnFirstUseWithMissingBroker()
        {
            var connectionFactory = new SingleConnectionFactory("foo");
            connectionFactory.Port = 434343;
            var applicationContext = new GenericApplicationContext();
            applicationContext.ObjectFactory.RegisterSingleton("foo", new Queue("queue"));
            var rabbitAdmin = new RabbitAdmin(connectionFactory);
            rabbitAdmin.ApplicationContext = applicationContext;
            rabbitAdmin.AutoStartup = true;
            rabbitAdmin.AfterPropertiesSet();

            try
            {
                rabbitAdmin.DeclareQueue();
            }
            catch (Exception ex)
            {
                Assert.True(ex is AmqpIOException, "Expecting an AmqpIOException");
            }
        }
        private void AssertExpectedObjectsAreRegisteredWith(GenericApplicationContext context, int expectedDefinitionCount)
        {
            // only check names that are not part of configuration namespace test
            List <string> names = new List <string>(context.DefaultListableObjectFactory.GetObjectDefinitionNames());

            names.RemoveAll(x => x.StartsWith("ConfigurationNameSpace"));


            if (names.Count != expectedDefinitionCount)
            {
                Console.WriteLine("Actual types registered with the container:");
                foreach (var name in names)
                {
                    Console.WriteLine(name);
                }
            }


            Assert.That(names.Count, Is.EqualTo(expectedDefinitionCount));
        }
Beispiel #33
0
    static void Main()
    {
        #region ContainerConfiguration
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Spring");

        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
        busConfiguration.UseContainer<SpringBuilder>(c => c.ExistingApplicationContext(applicationContext));
        #endregion
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        using (IBus bus = Bus.Create(busConfiguration).Start())
        {
            bus.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
    }
        public void ClearWithDynamicProxies()
        {
            CompositionProxyTypeBuilder typeBuilder = new CompositionProxyTypeBuilder();

            typeBuilder.TargetType = typeof(TestObject);
            Type proxyType = typeBuilder.BuildProxyType();

            DefaultListableObjectFactory of  = new DefaultListableObjectFactory();
            RootObjectDefinition         od1 = new RootObjectDefinition(proxyType, false);

            od1.PropertyValues.Add("Name", "Bruno");
            of.RegisterObjectDefinition("testObject", od1);

            GenericApplicationContext ctx1 = new GenericApplicationContext(of);

            ContextRegistry.RegisterContext(ctx1);

            ITestObject to1 = ContextRegistry.GetContext().GetObject("testObject") as ITestObject;

            Assert.IsNotNull(to1);
            Assert.AreEqual("Bruno", to1.Name);

            DefaultListableObjectFactory of2 = new DefaultListableObjectFactory();
            RootObjectDefinition         od2 = new RootObjectDefinition(proxyType, false);

            od2.PropertyValues.Add("Name", "Baia");
            of2.RegisterObjectDefinition("testObject", od2);
            GenericApplicationContext ctx2 = new GenericApplicationContext(of2);

            ContextRegistry.Clear();

            ITestObject to2 = ctx2.GetObject("testObject") as ITestObject;

            Assert.IsNotNull(to2);
            Assert.AreEqual("Baia", to2.Name);
        }
        public void SimpleReader()
        {
            GenericApplicationContext applicationContext = new GenericApplicationContext();


            IObjectDefinitionReader objectDefinitionReader = new XmlObjectDefinitionReader(applicationContext);

            objectDefinitionReader.LoadObjectDefinitions("assembly://foo");

            applicationContext.Refresh();
            

        }
        public void Simple()
        {
            GenericApplicationContext ctx = new GenericApplicationContext();
            IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory();

            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory,
                                                                                           typeof (TestObject));
            
            builder.AddPropertyValue("Age", 22)
                .AddPropertyValue("Name", "Joe")
                .AddPropertyReference("Spouse", "Spouse")
                .SetSingleton(false);
            
            ctx.RegisterObjectDefinition("TestObject", builder.ObjectDefinition);

            builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(TestObject));

            IList friends = new ArrayList();
            friends.Add(new TestObject("Dan", 34));
            friends.Add(new TestObject("Mary", 33));
            builder.AddPropertyValue("Friends", friends)
                .AddConstructorArg("Susan")
                .AddConstructorArg(23)
                .SetSingleton(false);

           ctx.RegisterObjectDefinition("Spouse", builder.ObjectDefinition);


            

            TestObject to = ctx.GetObject("TestObject") as TestObject;

            Assert.IsNotNull(to);

            Assert.AreEqual("Joe", to.Name);
            Assert.AreEqual(22, to.Age);
            Assert.AreEqual(2,to.Spouse.Friends.Count);
            Assert.AreEqual(23, to.Spouse.Age);

            /*
            AbstractApplicationContext ctx = ContextRegistry.GetContext() as AbstractApplicationContext;



            //XmlObjectFactory objectFactory = ctx.ObjectFactory as XmlObjectFactory;

            IObjectFactory objectFactory = ctx.ObjectFactory;

            //DefaultListableObjectFactory
            if (objectFactory != null)
            {
                Console.WriteLine("hi");
            }
            //objectFactory.RegisterObjectDefinition("TestObject", builder.ObjectDefinition);
             */
                



        }
 /// <summary>
 /// Scans for types using the default scanner.
 /// </summary>
 /// <param name="context">The context.</param>
 public static void ScanAllAssemblies(this GenericApplicationContext context)
 {
     Scan(context, new AssemblyObjectDefinitionScanner());
 }
 /// <summary>
 /// Scans for types that satisfy specified predicates.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="assemblyPredicate">The assembly predicate.</param>
 /// <param name="typePredicate">The type predicate.</param>
 public static void Scan(this GenericApplicationContext context, Func <Assembly, bool> assemblyPredicate, Func <Type, bool> typePredicate)
 {
     Scan(context, null, assemblyPredicate, typePredicate);
 }
 /// <summary>
 /// Scans for types that satisfy specified predicates.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="assemblyPredicate">The assembly predicate.</param>
 /// <param name="typePredicate">The type predicate.</param>
 public static void Scan(this GenericApplicationContext context, Predicate <Assembly> assemblyPredicate, Predicate <Type> typePredicate)
 {
     Scan(context, null, assemblyPredicate, typePredicate);
 }
 /// <summary>
 /// Scans for types that satisfy specified predicates located in the specified scan path.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="assemblyScanPath">The assembly scan path.</param>
 /// <param name="assemblyPredicate">The assembly predicate.</param>
 /// <param name="typePredicate">The type predicate.</param>
 public static void Scan(this GenericApplicationContext context, string assemblyScanPath, Func <Assembly, bool> assemblyPredicate,
                         Func <Type, bool> typePredicate)
 {
     Scan(context, assemblyScanPath, assemblyPredicate, typePredicate, new string[0]);
 }
 /// <summary>
 /// Scans the with assembly filter.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="assemblyPredicate">The assembly predicate.</param>
 public static void ScanWithAssemblyFilter(this GenericApplicationContext context, Predicate <Assembly> assemblyPredicate)
 {
     Scan(context, null, assemblyPredicate, delegate { return(true); });
 }
 /// <summary>
 /// Scans the with type filter.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="typePredicate">The type predicate.</param>
 public static void ScanWithTypeFilter(this GenericApplicationContext context, Func <Type, bool> typePredicate)
 {
     Scan(context, null, obj => true, typePredicate);
 }
 /// <summary>
 /// Scans the with assembly filter.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="assemblyPredicate">The assembly predicate.</param>
 public static void ScanWithAssemblyFilter(this GenericApplicationContext context, Func <Assembly, bool> assemblyPredicate)
 {
     Scan(context, null, assemblyPredicate, obj => true);
 }
 /// <summary>
 /// Instantiates the builder using the given container.
 /// </summary>
 /// <param name="container"></param>
 public SpringObjectBuilder(GenericApplicationContext container)
 {
     context = container;
 }
        public static Configure SpringFrameworkBuilder(this Configure config,GenericApplicationContext applicationContext)
        {
            ConfigureCommon.With(config, new SpringObjectBuilder(applicationContext));

            return config;
        }
 /// <summary>
 /// Scans the with type filter.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="typePredicate">The type predicate.</param>
 public static void ScanWithTypeFilter(this GenericApplicationContext context, Predicate <Type> typePredicate)
 {
     Scan(context, null, delegate { return(true); }, typePredicate);
 }