From 68b67e3f45a30039c3466f548fe9a698ff32f4d4 Mon Sep 17 00:00:00 2001 From: Marko Lahma Date: Sat, 24 Mar 2012 13:29:11 +0200 Subject: [PATCH] Fix remaining issues that were spotted by build and test system --- .../src/Spring.AopQuickStart.Step7/Program.cs | 4 +-- .../TxQuickStart/AccountManagerTests.cs | 5 ++-- .../Support/AbstractApplicationContext.cs | 2 +- .../Support/GenericApplicationContext.cs | 28 +++++++++---------- .../Support/DefaultListableObjectFactory.cs | 2 +- .../Support/StaticListableObjectFactory.cs | 24 +++++++++++----- .../Spring.Web.Mvc/SpringControllerFactory.cs | 6 ++-- .../SpringMvcDependencyResolver.cs | 4 +-- 8 files changed, 41 insertions(+), 34 deletions(-) diff --git a/examples/Spring/Spring.AopQuickStart/src/Spring.AopQuickStart.Step7/Program.cs b/examples/Spring/Spring.AopQuickStart/src/Spring.AopQuickStart.Step7/Program.cs index d3743d27..ac68e6c0 100644 --- a/examples/Spring/Spring.AopQuickStart/src/Spring.AopQuickStart.Step7/Program.cs +++ b/examples/Spring/Spring.AopQuickStart/src/Spring.AopQuickStart.Step7/Program.cs @@ -21,7 +21,7 @@ #region Imports using System; -using System.Collections; +using System.Collections.Generic; using Spring.Context; using Spring.Context.Support; @@ -47,7 +47,7 @@ namespace Spring.AopQuickStart { // Create AOP proxy using Spring.NET IoC container. IApplicationContext ctx = ContextRegistry.GetContext(); - IDictionary commands = ctx.GetObjectsOfType(typeof(ICommand)); + IDictionary commands = ctx.GetObjectsOfType(); foreach (ICommand command in commands.Values) { diff --git a/examples/Spring/Spring.TxQuickStart/test/Spring/Spring.TxQuickStart.Tests/TxQuickStart/AccountManagerTests.cs b/examples/Spring/Spring.TxQuickStart/test/Spring/Spring.TxQuickStart.Tests/TxQuickStart/AccountManagerTests.cs index d9bfead1..7bc7be33 100644 --- a/examples/Spring/Spring.TxQuickStart/test/Spring/Spring.TxQuickStart.Tests/TxQuickStart/AccountManagerTests.cs +++ b/examples/Spring/Spring.TxQuickStart/test/Spring/Spring.TxQuickStart.Tests/TxQuickStart/AccountManagerTests.cs @@ -21,7 +21,7 @@ #region Imports using System; -using System.Collections; +using System.Collections.Generic; using System.Data; using NUnit.Framework; using Spring.Aop.Config; @@ -30,7 +30,6 @@ using Spring.Context.Support; using Spring.Data.Common; using Spring.Data.Config; using Spring.Data.Core; -using Spring.Objects.Factory.Support; using Spring.Objects.Factory.Xml; using Spring.Transaction.Config; using Spring.TxQuickStart.Services; @@ -55,7 +54,7 @@ namespace Spring.TxQuickStart NamespaceParserRegistry.RegisterParser(typeof(TxNamespaceParser)); NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser)); IApplicationContext context = CreateContextFromXml(); - IDictionary dict = context.GetObjectsOfType(typeof (IAccountManager)); + IDictionary dict = context.GetObjectsOfType(); accountManager = context["accountManager"] as IAccountManager; CleanDb(context); } diff --git a/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs b/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs index a7d80da3..42e31143 100644 --- a/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs +++ b/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs @@ -1444,7 +1444,7 @@ namespace Spring.Context.Support /// public IDictionary GetObjectsOfType() { - return (IDictionary) GetObjectsOfType(typeof(T)); + return ObjectFactory.GetObjectsOfType(true, true); } /// diff --git a/src/Spring/Spring.Core/Context/Support/GenericApplicationContext.cs b/src/Spring/Spring.Core/Context/Support/GenericApplicationContext.cs index 7b29ec14..cef3d73c 100644 --- a/src/Spring/Spring.Core/Context/Support/GenericApplicationContext.cs +++ b/src/Spring/Spring.Core/Context/Support/GenericApplicationContext.cs @@ -1,19 +1,19 @@ #region License -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #endregion diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs index 20eca0d3..b30915d7 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs @@ -27,7 +27,7 @@ using System.Collections.Specialized; using System.Globalization; using Common.Logging; -using Spring.Collections.Generic; + using Spring.Core; using Spring.Core.TypeConversion; using Spring.Objects.Factory.Config; diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/StaticListableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/StaticListableObjectFactory.cs index 6342512f..03244397 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/StaticListableObjectFactory.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/StaticListableObjectFactory.cs @@ -19,6 +19,7 @@ #region Imports using System; +using System.Collections; using System.Collections.Generic; using Spring.Objects.Factory.Config; @@ -817,7 +818,9 @@ namespace Spring.Objects.Factory.Support /// public IDictionary GetObjectsOfType() { - return (IDictionary) GetObjectsOfType(typeof(T)); + Dictionary collector = new Dictionary(); + DoGetObjectsOfType(typeof(T), true, true, collector); + return collector; } /// @@ -847,9 +850,15 @@ namespace Spring.Objects.Factory.Support /// If the objects could not be created. /// public IDictionary GetObjectsOfType(Type type, bool includePrototypes, bool includeFactoryObjects) + { + Dictionary collector = new Dictionary(); + DoGetObjectsOfType(type, includeFactoryObjects, includePrototypes, collector); + return collector; + } + + private void DoGetObjectsOfType(Type type, bool includeFactoryObjects, bool includePrototypes, IDictionary collector) { bool isFactoryType = (type != null && typeof(IFactoryObject).IsAssignableFrom(type)); - IDictionary matches = new Dictionary(); foreach (string name in objects.Keys) { object instance = objects[name]; @@ -864,7 +873,7 @@ namespace Spring.Objects.Factory.Support object createdObject = GetObject(name); if (type.IsInstanceOfType(createdObject)) { - matches[name] = createdObject; + collector[name] = createdObject; } } } @@ -872,15 +881,14 @@ namespace Spring.Objects.Factory.Support { if (isFactoryType) { - matches[ObjectFactoryUtils.BuildFactoryObjectName(name)] = instance; + collector[ObjectFactoryUtils.BuildFactoryObjectName(name)] = instance; } else { - matches[name] = instance; + collector[name] = instance; } } } - return matches; } /// @@ -911,7 +919,9 @@ namespace Spring.Objects.Factory.Support /// public IDictionary GetObjectsOfType(bool includePrototypes, bool includeFactoryObjects) { - return (IDictionary) GetObjectsOfType(typeof(T), includePrototypes, includeFactoryObjects); + Dictionary collector = new Dictionary(); + DoGetObjectsOfType(typeof(T), includeFactoryObjects, includePrototypes, collector); + return collector; } /// diff --git a/src/Spring/Spring.Web.Mvc/SpringControllerFactory.cs b/src/Spring/Spring.Web.Mvc/SpringControllerFactory.cs index f36c2071..e1acf477 100644 --- a/src/Spring/Spring.Web.Mvc/SpringControllerFactory.cs +++ b/src/Spring/Spring.Web.Mvc/SpringControllerFactory.cs @@ -21,12 +21,10 @@ using System; using System.Web.Mvc; using System.Web.Routing; -using Spring.Objects.Factory; -using Spring.Core; + using Spring.Context; using Spring.Context.Support; using System.Linq; -using System.Collections; namespace Spring.Web.Mvc { @@ -116,7 +114,7 @@ namespace Spring.Web.Mvc var controllers = ApplicationContext.GetObjectsOfType(controllerType); if (controllers.Count > 0) { - controller = (IController)controllers.Cast().First().Value; + controller = (IController)controllers.First().Value; } } diff --git a/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs b/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs index 6210c6d1..42f660b6 100644 --- a/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs +++ b/src/Spring/Spring.Web.Mvc3/SpringMvcDependencyResolver.cs @@ -74,7 +74,7 @@ namespace Spring.Web.Mvc var services = ApplicationContext.GetObjectsOfType(serviceType); if (services.Count > 0) { - service = services.Cast().First().Value; + service = services.First().Value; } } @@ -89,7 +89,7 @@ namespace Spring.Web.Mvc public IEnumerable GetServices(Type serviceType) { var services = ApplicationContext.GetObjectsOfType(serviceType); - return services.Values.Cast(); + return services.Values; } } }