From 8c58b7281c73ba1d7325de8464c8a0f3741be7c4 Mon Sep 17 00:00:00 2001 From: cneuwirt Date: Thu, 20 Mar 2008 14:34:00 +0000 Subject: [PATCH] Added a few overloads to AddFacility to be consistent with AddComponent. git-svn-id: https://svn.castleproject.org/svn/castle/trunk@4922 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- ...omponents.DictionaryAdapter.Tests-vs2008.csproj | 2 +- ...stle.Components.DictionaryAdapter-vs2008.csproj | 3 ++- .../Castle.MicroKernel/DefaultKernel.cs | 10 ++++++++++ InversionOfControl/Castle.MicroKernel/IKernel.cs | 13 ++++++++++++ .../Registration/ServiceOverrideDescriptor.cs | 6 +++--- .../Castle.Windsor/IWindsorContainer.cs | 17 +++++++++++++++- .../Castle.Windsor/WindsorContainer.cs | 23 ++++++++++++++++++++++ InversionOfControl/Changes.txt | 2 ++ 8 files changed, 70 insertions(+), 6 deletions(-) diff --git a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/Castle.Components.DictionaryAdapter.Tests-vs2008.csproj b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/Castle.Components.DictionaryAdapter.Tests-vs2008.csproj index 0117ee08b..58887e5df 100644 --- a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/Castle.Components.DictionaryAdapter.Tests-vs2008.csproj +++ b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter.Tests/Castle.Components.DictionaryAdapter.Tests-vs2008.csproj @@ -51,7 +51,7 @@ False - ..\..\..\..\SharedLibs\net\2.0\nunit.framework.dll + ..\..\..\SharedLibs\net\2.0\nunit.framework.dll diff --git a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj index 826dd1eda..c3e1610a4 100644 --- a/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj +++ b/Components/DictionaryAdapter/Castle.Components.DictionaryAdapter/Castle.Components.DictionaryAdapter-vs2008.csproj @@ -30,6 +30,8 @@ false true v3.5 + true + ..\..\..\CastleKey.snk true @@ -86,7 +88,6 @@ - diff --git a/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs b/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs index f2782f2fc..a1f92f752 100644 --- a/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs +++ b/InversionOfControl/Castle.MicroKernel/DefaultKernel.cs @@ -1115,6 +1115,16 @@ namespace Castle.MicroKernel facilities.Add(facility); } + public void AddFacility(String key) where T : IFacility, new() + { + AddFacility(key, new T()); + } + + public void AddFacility() where T : IFacility, new() + { + AddFacility(typeof(T).FullName); + } + /// /// Returns the facilities registered on the kernel. /// diff --git a/InversionOfControl/Castle.MicroKernel/IKernel.cs b/InversionOfControl/Castle.MicroKernel/IKernel.cs index 27707859e..6324d1f02 100644 --- a/InversionOfControl/Castle.MicroKernel/IKernel.cs +++ b/InversionOfControl/Castle.MicroKernel/IKernel.cs @@ -559,6 +559,19 @@ namespace Castle.MicroKernel void AddFacility(String key, IFacility facility); /// + /// Creates and adds an facility to the kernel. + /// + /// The facility type. + /// + void AddFacility(String key) where T : IFacility, new(); + + /// + /// Creates and adds an facility to the kernel. + /// + /// The facility type. + void AddFacility() where T : IFacility, new(); + + /// /// Returns the facilities registered on the kernel. /// /// diff --git a/InversionOfControl/Castle.MicroKernel/Registration/ServiceOverrideDescriptor.cs b/InversionOfControl/Castle.MicroKernel/Registration/ServiceOverrideDescriptor.cs index 512244d6a..32572e516 100644 --- a/InversionOfControl/Castle.MicroKernel/Registration/ServiceOverrideDescriptor.cs +++ b/InversionOfControl/Castle.MicroKernel/Registration/ServiceOverrideDescriptor.cs @@ -60,7 +60,7 @@ namespace Castle.MicroKernel.Registration } private void ApplyReferenceList(IKernel kernel, ComponentModel model, - String key, IEnumerable componentKeys, + String key, IEnumerable items, ServiceOverride serviceOverride) { MutableConfiguration list = new MutableConfiguration("list"); @@ -70,9 +70,9 @@ namespace Castle.MicroKernel.Registration list.Attributes.Add("type", serviceOverride.Type.AssemblyQualifiedName); } - foreach (String componentKey in componentKeys ) + foreach (String item in items ) { - String reference = FormattedReferenceExpression(componentKey); + String reference = FormattedReferenceExpression(item); MutableConfiguration node = new MutableConfiguration("item", reference); list.Children.Add(node); } diff --git a/InversionOfControl/Castle.Windsor/IWindsorContainer.cs b/InversionOfControl/Castle.Windsor/IWindsorContainer.cs index 6e699cce4..c4f7f96b6 100644 --- a/InversionOfControl/Castle.Windsor/IWindsorContainer.cs +++ b/InversionOfControl/Castle.Windsor/IWindsorContainer.cs @@ -36,13 +36,28 @@ namespace Castle.Windsor string Name { get; } /// - /// Registers a facility within the kernel. + /// Registers a facility within the container. /// /// The key by which the gets indexed. /// The to add to the container. IWindsorContainer AddFacility(String key, IFacility facility); /// + /// Creates and adds an facility to the container. + /// + /// The facility type. + /// + /// + IWindsorContainer AddFacility(String key) where T : IFacility, new(); + + /// + /// Creates and adds an facility to the container. + /// + /// The facility type. + /// + IWindsorContainer AddFacility() where T : IFacility, new(); + + /// /// Adds a component to be managed by the container /// /// The key by which the component gets indexed. diff --git a/InversionOfControl/Castle.Windsor/WindsorContainer.cs b/InversionOfControl/Castle.Windsor/WindsorContainer.cs index 5747e5b25..0c21b7b8f 100644 --- a/InversionOfControl/Castle.Windsor/WindsorContainer.cs +++ b/InversionOfControl/Castle.Windsor/WindsorContainer.cs @@ -259,6 +259,29 @@ namespace Castle.Windsor } /// + /// Creates and adds an facility to the container. + /// + /// The facility type. + /// + /// + public IWindsorContainer AddFacility(String key) where T : IFacility, new() + { + kernel.AddFacility(key); + return this; + } + + /// + /// Creates and adds an facility to the container. + /// + /// The facility type. + /// + public IWindsorContainer AddFacility() where T : IFacility, new() + { + kernel.AddFacility(); + return this; + } + + /// /// Adds a component to be managed by the container /// /// diff --git a/InversionOfControl/Changes.txt b/InversionOfControl/Changes.txt index 711c73ffb..3547c421c 100644 --- a/InversionOfControl/Changes.txt +++ b/InversionOfControl/Changes.txt @@ -1,6 +1,8 @@ RC 4 ==== +- Added generic AddFacility methods to kernel. + - Added generalized configuration support to ComponentRegistration. - Added IWindsorInstaller interface to enhance Windsor component installation. -- 2.11.4.GIT