From 8f2bda0eed1e87e9f2558de0a6569312a2a2f020 Mon Sep 17 00:00:00 2001 From: hammett Date: Thu, 23 Aug 2007 17:25:23 +0000 Subject: [PATCH] - Applied Ron Grabowski's patch fixing IOC-89 "Make DefaultKernel implement IServiceProvider" Changed to make it implement explicitly IServiceProviderEx git-svn-id: https://svn.castleproject.org/svn/castle/trunk@4183 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../Castle.MicroKernel/DefaultKernel.cs | 43 +++++++++++++++++++--- InversionOfControl/Castle.MicroKernel/IKernel.cs | 6 +-- .../Castle.Windsor/IWindsorContainer.cs | 2 +- .../Castle.Windsor/WindsorContainer.cs | 28 ++++++++++++++ InversionOfControl/Changes.txt | 3 ++ 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs b/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs index 7136bf0d1..6a7f9f206 100644 --- a/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs +++ b/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs @@ -547,17 +547,17 @@ namespace Castle.MicroKernel /// /// /// - public T Resolve(IDictionary arguments) where T : class + public T Resolve(IDictionary arguments) { Type serviceType = typeof(T); - return Resolve(serviceType, arguments) as T; + return (T) Resolve(serviceType, arguments); } /// /// Returns the component instance by the component key /// /// - public T Resolve() where T : class + public T Resolve() { Type serviceType = typeof(T); return (T) Resolve(serviceType); @@ -793,10 +793,13 @@ namespace Castle.MicroKernel { List services = new List(); IHandler[] handlers = GetHandlers(typeof(TService)); + foreach(IHandler handler in handlers) { if (handler.CurrentState == HandlerState.Valid) + { services.Add((TService) ResolveComponent(handler)); + } } return services.ToArray(); @@ -1107,6 +1110,37 @@ namespace Castle.MicroKernel #endregion + #region IServiceProviderEx Members + + /// + /// Gets the service object of the specified type. + /// + /// + /// + /// A service object of type serviceType. + /// + /// + /// An object that specifies the type of service object to get. + public object GetService(Type serviceType) + { + return Resolve(serviceType); + } + + /// + /// Gets the service object of the specified type. + /// + /// + /// + /// A service object of type serviceType. + /// + public T GetService() + { + Type serviceType = typeof(T); + return (T) Resolve(serviceType); + } + + #endregion + #region IDisposable Members /// @@ -1281,6 +1315,5 @@ namespace Castle.MicroKernel } #endregion - } -} \ No newline at end of file +} diff --git a/InversionOfControl/Castle.MicroKernel/IKernel.cs b/InversionOfControl/Castle.MicroKernel/IKernel.cs index f3adfdec2..4f9894598 100644 --- a/InversionOfControl/Castle.MicroKernel/IKernel.cs +++ b/InversionOfControl/Castle.MicroKernel/IKernel.cs @@ -31,7 +31,7 @@ namespace Castle.MicroKernel /// /// /// - public interface IKernel : IKernelEvents, IDisposable + public interface IKernel : IServiceProviderEx, IKernelEvents, IDisposable { /// /// Adds a concrete class as a component @@ -356,13 +356,13 @@ namespace Castle.MicroKernel /// /// /// - T Resolve(IDictionary arguments) where T : class; + T Resolve(IDictionary arguments); /// /// Returns the component instance by the component key /// /// - T Resolve() where T : class; + T Resolve(); /// /// Returns component instances that implement TService diff --git a/InversionOfControl/Castle.Windsor/IWindsorContainer.cs b/InversionOfControl/Castle.Windsor/IWindsorContainer.cs index 15bdee7cc..c83e64e67 100644 --- a/InversionOfControl/Castle.Windsor/IWindsorContainer.cs +++ b/InversionOfControl/Castle.Windsor/IWindsorContainer.cs @@ -23,7 +23,7 @@ namespace Castle.Windsor /// The IWindsorContainer interface exposes all the /// functionality the Windsor implements. /// - public interface IWindsorContainer : IDisposable + public interface IWindsorContainer : IServiceProviderEx, IDisposable { /// /// Gets the container's name diff --git a/InversionOfControl/Castle.Windsor/WindsorContainer.cs b/InversionOfControl/Castle.Windsor/WindsorContainer.cs index fa107c4a2..a9cebf9b2 100644 --- a/InversionOfControl/Castle.Windsor/WindsorContainer.cs +++ b/InversionOfControl/Castle.Windsor/WindsorContainer.cs @@ -646,6 +646,34 @@ namespace Castle.Windsor #endregion + #region IServiceProviderEx Members + + /// + /// Gets the service object of the specified type. + /// + /// + /// A service object of type serviceType. + /// + /// An object that specifies the type of service object to get. + public object GetService(Type serviceType) + { + return kernel.Resolve(serviceType); + } + + /// + /// Gets the service object of the specified type. + /// + /// + /// A service object of type serviceType. + /// + public T GetService() + { + Type serviceType = typeof(T); + return (T) kernel.Resolve(serviceType); + } + + #endregion + #region IDisposable Members /// diff --git a/InversionOfControl/Changes.txt b/InversionOfControl/Changes.txt index 6699de2d0..9e6fd2e8c 100644 --- a/InversionOfControl/Changes.txt +++ b/InversionOfControl/Changes.txt @@ -1,6 +1,9 @@ RC 4 ==== +- Applied Ron Grabowski's patch fixing IOC-89 + "Make DefaultKernel implement IServiceProvider" + - Check for required Properties before determining the Handlers initial state - Fixed IoC-87 -- 2.11.4.GIT