using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Spring.Context; using Spring.Context.Support; using Spring.Objects; using Spring.Objects.Factory; using System.Collections; using log4net; namespace Sleis.Infrastructure { public static class SpringServiceProvider { private static readonly ILog _log = LogManager.GetLogger(typeof(SpringServiceProvider)); private static readonly IApplicationContext context; static SpringServiceProvider() { context = ContextRegistry.GetContext() as IApplicationContext; _log.InfoFormat("Context Loaded On: {0} Objects: {1}", context.StartupDate, context.ObjectDefinitionCount); _log.Info("Initializing lookups...."); Utility.LookupUtility.Init(); _log.Info("Done initializing lookups"); } public static T GetService() { return GetServices().FirstOrDefault(); } public static T GetService(string name) { T obj = (T)context.GetObject(name); _log.DebugFormat("Service: {0} from Context: {1}, Object: {2}", name, context.StartupDate, obj); return obj; } public static IEnumerable GetServices() { List list = new List(); foreach (string name in context.GetObjectNamesForType(typeof(T))) { _log.DebugFormat("Service Type: {0} from Context: {1}", typeof(T).Name, context.StartupDate); list.Add(GetService(name)); } return list; } } }