public void GenericApplicationContextConstructorTests()
        {
            IApplicationContext       ctx        = new XmlApplicationContext("assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context/contextlifecycle.xml");
            GenericApplicationContext genericCtx = new GenericApplicationContext(ctx);

            genericCtx = new GenericApplicationContext("test", true, ctx);
        }
        /// <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);
        }
        /// <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 GenericApplicationContextWithXmlObjectDefinitions()
        {
            GenericApplicationContext ctx    = new GenericApplicationContext();
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(ctx);

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

            Assert.IsTrue(ctx.ContainsObject("service"));
            Assert.IsTrue(ctx.ContainsObject("logicOne"));
            Assert.IsTrue(ctx.ContainsObject("logicTwo"));
            ctx.Dispose();
        }
        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));
        }
Пример #6
0
        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);
        }
 /// <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 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 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);
 }