Author: hammett
Date: Sun Jul 4 19:37:03 2004
New Revision: 22581
Modified:
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Handler/AbstractHandler.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/AbstractHandlerTestCase.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Subsystems/Events/EventManagerData.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/TODO.txt
Log:
Initial work to extract AOP from Kernel
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs Sun Jul 4 19:37:03 2004
@@ -29,10 +29,6 @@
/// </summary>
public class BaseKernel : Kernel
{
- protected ArrayList m_aspectBefore;
-
- protected ArrayList m_aspectAfter;
-
protected Hashtable m_components;
protected Hashtable m_services;
@@ -52,15 +48,13 @@
/// </summary>
public BaseKernel()
{
- m_aspectBefore = new ArrayList();
- m_aspectAfter = new ArrayList();
- m_components = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
m_services = new Hashtable();
- m_dependencyToSatisfy = new Hashtable();
+ m_components = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
m_subsystems = new Hashtable();
m_handlerFactory = new Handler.Default.SimpleHandlerFactory();
- m_lifestyleManagerFactory = new Lifestyle.Default.SimpleLifestyleManagerFactory();
+ m_dependencyToSatisfy = new Hashtable();
m_componentModelBuilder = new Model.Default.DefaultComponentModelBuilder( this );
+ m_lifestyleManagerFactory = new Lifestyle.Default.SimpleLifestyleManagerFactory();
AddSubsystem( KernelConstants.LOOKUP, new LookupCriteriaMatcher() );
AddSubsystem( KernelConstants.EVENTS, new EventManager() );
@@ -112,6 +106,7 @@
{
AssertUtil.ArgumentNotNull( aspect, "aspect" );
+ /*
if ((AspectPointCutFlags.Before & flags) != 0)
{
lock(m_aspectBefore)
@@ -126,6 +121,7 @@
m_aspectAfter.Add( aspect );
}
}
+ */
}
/// <summary>
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Handler/AbstractHandler.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Handler/AbstractHandler.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Handler/AbstractHandler.cs Sun Jul 4 19:37:03 2004
@@ -18,6 +18,7 @@
using System.Collections;
using Apache.Avalon.Castle.MicroKernel.Model;
+ using Apache.Avalon.Castle.MicroKernel.Subsystems.Events;
/// <summary>
/// Summary description for AbstractHandler.
@@ -68,7 +69,7 @@
{
object instance = m_lifestyleManager.Resolve();
- RegisterInstance( instance );
+ RegisterInstance( ref instance );
return instance;
}
@@ -105,9 +106,9 @@
#endregion
- protected virtual void RegisterInstance( object instance )
+ protected virtual void RegisterInstance( ref object instance )
{
- RaiseComponentCreatedEvent( instance );
+ RaiseComponentCreatedEvent( ref instance );
if (!HasInstance( instance, false ))
{
@@ -151,6 +152,34 @@
}
return false;
+ }
+
+ protected virtual void RaiseComponentCreatedEvent( ref object instance )
+ {
+ IEventManager eventManager = (IEventManager) m_kernel.GetSubsystem( KernelConstants.EVENTS );
+
+ if (eventManager != null)
+ {
+ // We're passing the instance and allowing the listeners to
+ // replace/wrap the instance as they wish.
+ EventManagerData data = new EventManagerData( m_componentModel, instance );
+
+ eventManager.OnComponentCreated( data );
+
+ /// 90% of cases we're setting the same instance back
+ instance = data.Instance;
+ }
+ }
+
+ protected virtual void RaiseComponentCreatedEvent( object instance )
+ {
+ IEventManager eventManager = (IEventManager) m_kernel.GetSubsystem( KernelConstants.EVENTS );
+
+ if (eventManager != null)
+ {
+ EventManagerData data = new EventManagerData( m_componentModel, instance );
+ eventManager.OnComponentDestroyed( data );
+ }
}
}
}
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/AbstractHandlerTestCase.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/AbstractHandlerTestCase.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/AbstractHandlerTestCase.cs Sun Jul 4 19:37:03 2004
@@ -46,6 +46,7 @@
public void TransientReferences()
{
MyHandler handler = new MyHandler( model );
+ handler.Init( kernel );
object instance = handler.Resolve();
AssertNotNull( instance );
@@ -61,6 +62,7 @@
public void MultipleTransientReferences()
{
MyHandler handler = new MyHandler( model );
+ handler.Init( kernel );
object instance1 = handler.Resolve();
object instance2 = handler.Resolve();
@@ -92,7 +94,7 @@
public override object Resolve()
{
object instance = new object();
- base.RegisterInstance( instance );
+ base.RegisterInstance( ref instance );
return instance;
}
@@ -109,6 +111,7 @@
public void SingletonReferences()
{
MySingletonHandler handler = new MySingletonHandler( model );
+ handler.Init( kernel );
object instance1 = handler.Resolve();
object instance2 = handler.Resolve();
@@ -136,7 +139,7 @@
public override object Resolve()
{
- base.RegisterInstance( instance );
+ base.RegisterInstance( ref instance );
return instance;
}
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Subsystems/Events/EventManagerData.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Subsystems/Events/EventManagerData.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Subsystems/Events/EventManagerData.cs Sun Jul 4 19:37:03 2004
@@ -16,6 +16,8 @@
{
using System;
+ using Apache.Avalon.Castle.MicroKernel.Model;
+
/// <summary>
///
/// </summary>
@@ -39,6 +41,18 @@
m_instance = componentInstance;
}
+ public EventManagerData( IComponentModel model )
+ {
+ m_componentName = model.Name;
+ m_service = model.Service;
+ m_implementation = model.ConstructionModel.Implementation;
+ }
+
+ public EventManagerData( IComponentModel model, object instance ) : this( model )
+ {
+ m_instance = instance;
+ }
+
public String ComponentName
{
get
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/TODO.txt
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/TODO.txt (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/TODO.txt Sun Jul 4 19:37:03 2004
@@ -1,5 +1,7 @@
-- Add support to AvalonConfigurationAttribute
-- Add support to AvalonStageAttribute
-- Add support to AvalonExtensionAttribute
-- Add support to AvalonContextAttribute
-- Add support to AvalonEntryAttribute
+- Add subsystem to handle AOP/Interceptors
+
+- Add support to AvalonConfigurationAttribute
+- Add support to AvalonStageAttribute
+- Add support to AvalonExtensionAttribute
+- Add support to AvalonContextAttribute
+- Add support to AvalonEntryAttribute
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.