User: xtoff
Date: 2009/12/18 01:39 PM
Modified:
/InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Lifestyle/
LifestyleManagerTestCase.cs
/InversionOfControl/trunk/src/Castle.MicroKernel/
DefaultKernel.cs
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/
DefaultConfigurationStore.cs
Log:
- fixed IOC-ISSUE-160 - Re-registration of a Named component mantains previous
Lifestyle.
Turns out kernel.RemoveComponent would not clean up configuration from
configuration store.
I'm not sure that was deliberate and if that change can break anyone. All the
tests pass so I think it's good to go.
File Changes:
Directory: /InversionOfControl/trunk/src/Castle.MicroKernel/
============================================================
File [modified]: DefaultKernel.cs
Delta lines: +26 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/DefaultConfigurationStore.cs
2009-12-18 18:18:19 UTC (rev 6455)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/DefaultConfigurationStore.cs
2009-12-18 20:39:56 UTC (rev 6456)
@@ -46,6 +46,32 @@
{
}
+ public override void Init(IKernel kernel)
+ {
+ base.Init(kernel);
+ Kernel.ComponentUnregistered +=
CleanUpComponentConfiguration;
+ }
+
+ private void CleanUpComponentConfiguration(string key, IHandler
handler)
+ {
+ if (key == null)
+ {
+ return;
+ }
+
+ if (components.Remove(key))
+ {
+ return;
+ }
+
+ bootstrapcomponents.Remove(key);
+ }
+
+ public override void Terminate()
+ {
+ Kernel.ComponentUnregistered -=
CleanUpComponentConfiguration;
+ }
+
/// <summary>
/// Associates a configuration node with a facility key
Directory:
/InversionOfControl/trunk/src/Castle.MicroKernel/SubSystems/Configuration/
=====================================================================================
File [modified]: DefaultConfigurationStore.cs
Delta lines: +20 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Lifestyle/LifestyleManagerTestCase.cs
2009-12-18 18:18:19 UTC (rev 6455)
+++
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Lifestyle/LifestyleManagerTestCase.cs
2009-12-18 20:39:56 UTC (rev 6456)
@@ -18,6 +18,8 @@
using System.Threading;
using Castle.Core;
using Castle.Core.Configuration;
+ using Castle.MicroKernel.Registration;
+ using Castle.MicroKernel.Tests.ClassComponents;
using Castle.MicroKernel.Tests.Lifestyle.Components;
using NUnit.Framework;
@@ -44,6 +46,24 @@
}
[Test]
+ public void
Reregistration_should_not_maintain_old_lifestyle_IoC_Issue_160()
+ {
+
kernel.Register(Component.For<ICommon>().ImplementedBy<CommonImpl1>().Named("foo").LifeStyle.Singleton);
+
+ var handler = kernel.GetHandler("foo");
+ Assert.AreEqual(LifestyleType.Singleton,
handler.ComponentModel.LifestyleType);
+
+ var removed = kernel.RemoveComponent("foo");
+ Assert.IsTrue(removed);
+
+ var registration =
Component.For<ICommon>().ImplementedBy<CommonImpl2>().Named("foo").LifeStyle.Transient;
+ kernel.Register(registration);
+
+ handler = kernel.GetHandler("foo");
+ Assert.AreEqual(LifestyleType.Transient,
handler.ComponentModel.LifestyleType);
+ }
+
+ [Test]
public void TestTransient()
{
Directory: /InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Lifestyle/
============================================================================
File [modified]: LifestyleManagerTestCase.cs
Delta lines: +0 -0
===================================================================
--
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=en.