svn commit: rev 37405 - in avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel: . MicroKernelTest Model Model/Default
[email protected] 2 Sep 2004 19:19:15 -0000
| Newsgroups | gmane.comp.jakarta.avalon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: hammett
Date: Thu Sep 2 12:19:13 2004
New Revision: 37405
Added:
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AbstractKernelEvents.cs (contents, props changed)
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelFacility.cs (contents, props changed)
Modified:
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/ (props changed)
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/BaseKernel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelEvents.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelSubsystem.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/KernelConstants.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/ComponentWrapperTestCase.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultAvalonKernelTestCase.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/KernelEventsTestCase.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultConstructionModel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultDependencyModel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IComponentModel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IConstructionModel.cs
avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IDependencyModel.cs
Log:
Refactoring. AbstractKernelEvents to handle all events code.
Added: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AbstractKernelEvents.cs
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/AbstractKernelEvents.cs Thu Sep 2 12:19:13 2004
@@ -0,0 +1,323 @@
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Apache.Avalon.Castle.MicroKernel
+{
+ using System;
+ using System.Collections;
+ using System.ComponentModel;
+
+ using Apache.Avalon.Framework;
+ using Apache.Avalon.Castle.MicroKernel.Model;
+ using Apache.Avalon.Castle.MicroKernel.Handler.Default;
+ using Apache.Avalon.Castle.MicroKernel.Lifestyle.Default;
+ using Apache.Avalon.Castle.MicroKernel.Model.Default;
+ using Apache.Avalon.Castle.MicroKernel.Interceptor;
+ using Apache.Avalon.Castle.MicroKernel.Interceptor.Default;
+
+ /// <summary>
+ /// Implements the basic <see cref="IKernelEvents"/> functionality.
+ /// </summary>
+ public abstract class AbstractKernelEvents : IKernelEvents
+ {
+ private static readonly object ComponentRegisteredEvent = new object();
+ private static readonly object ComponentUnregisteredEvent = new object();
+ private static readonly object ComponentWrapEvent = new object();
+ private static readonly object ComponentUnWrapEvent = new object();
+ private static readonly object ComponentReadyEvent = new object();
+ private static readonly object ComponentReleasedEvent = new object();
+ private static readonly object ComponentModelConstructedEvent = new object();
+
+ private EventHandlerList m_events;
+
+ protected Hashtable m_proxy2ComponentWrapper;
+
+ protected Hashtable m_service2Key;
+
+ protected Hashtable m_dependencyToSatisfy;
+
+ protected IInterceptedComponentBuilder m_interceptedComponentBuilder;
+
+ public AbstractKernelEvents()
+ {
+ m_events = new EventHandlerList();
+ m_service2Key = new Hashtable();
+ m_dependencyToSatisfy = new Hashtable();
+ m_proxy2ComponentWrapper = new Hashtable();
+ m_interceptedComponentBuilder = new DefaultInterceptedComponentBuilder();
+ }
+
+ #region IKernelEvents
+
+ /// <summary>
+ /// Pending
+ /// </summary>
+ /// <value></value>
+ public event ComponentDataDelegate ComponentRegistered
+ {
+ add { m_events.AddHandler(ComponentRegisteredEvent, value); }
+ remove { m_events.RemoveHandler(ComponentRegisteredEvent, value); }
+ }
+
+ /// <summary>
+ /// Pending
+ /// </summary>
+ /// <value></value>
+ public event ComponentDataDelegate ComponentUnregistered
+ {
+ add { m_events.AddHandler(ComponentUnregisteredEvent, value); }
+ remove { m_events.RemoveHandler(ComponentUnregisteredEvent, value); }
+ }
+
+ /// <summary>
+ /// Pending
+ /// </summary>
+ /// <value></value>
+ public event WrapDelegate ComponentWrap
+ {
+ add { m_events.AddHandler(ComponentWrapEvent, value); }
+ remove { m_events.RemoveHandler(ComponentWrapEvent, value); }
+ }
+
+ /// <summary>
+ /// Pending
+ /// </summary>
+ /// <value></value>
+ public event WrapDelegate ComponentUnWrap
+ {
+ add { m_events.AddHandler(ComponentUnWrapEvent, value); }
+ remove { m_events.RemoveHandler(ComponentUnWrapEvent, value); }
+ }
+
+ /// <summary>
+ /// Pending
+ /// </summary>
+ /// <value></value>
+ public event ComponentInstanceDelegate ComponentReady
+ {
+ add { m_events.AddHandler(ComponentReadyEvent, value); }
+ remove { m_events.RemoveHandler(ComponentReadyEvent, value); }
+ }
+
+ /// <summary>
+ /// Pending
+ /// </summary>
+ /// <value></value>
+ public event ComponentInstanceDelegate ComponentReleased
+ {
+ add { m_events.AddHandler(ComponentReleasedEvent, value); }
+ remove { m_events.RemoveHandler(ComponentReleasedEvent, value); }
+ }
+
+ /// <summary>
+ /// Pending
+ /// </summary>
+ /// <value></value>
+ public event ComponentModelDelegate ComponentModelConstructed
+ {
+ add { m_events.AddHandler(ComponentModelConstructedEvent, value); }
+ remove { m_events.RemoveHandler(ComponentModelConstructedEvent, value); }
+ }
+
+ public virtual void RaiseComponentReadyEvent(IHandler handler, object instance)
+ {
+ ComponentInstanceDelegate eventDelegate = (ComponentInstanceDelegate)m_events[ComponentReadyEvent];
+
+ if (eventDelegate != null)
+ {
+ IComponentModel model = handler.ComponentModel;
+ String key = (String)m_service2Key[model.Service];
+
+ eventDelegate(model, key, handler, instance);
+ }
+ }
+
+ public virtual void RaiseComponentReleasedEvent(IHandler handler, object instance)
+ {
+ ComponentInstanceDelegate eventDelegate = (ComponentInstanceDelegate)m_events[ComponentReleasedEvent];
+
+ if (eventDelegate != null)
+ {
+ IComponentModel model = handler.ComponentModel;
+ String key = (String)m_service2Key[model.Service];
+
+ eventDelegate(model, key, handler, instance);
+ }
+ }
+
+ public virtual object RaiseWrapEvent(IHandler handler, object instance)
+ {
+ WrapDelegate eventDelegate = (WrapDelegate)m_events[ComponentWrapEvent];
+
+ if (eventDelegate != null)
+ {
+ IComponentModel model = handler.ComponentModel;
+ String key = (String)m_service2Key[model.Service];
+ InterceptedComponentWrapper wrapper =
+ new InterceptedComponentWrapper(m_interceptedComponentBuilder, instance, model.Service);
+
+ eventDelegate(model, key, handler, wrapper);
+
+ if (wrapper.IsProxiedCreated)
+ {
+ object proxy = wrapper.ProxiedInstance;
+ m_proxy2ComponentWrapper[proxy] = wrapper;
+
+ // From now on, the outside world will have
+ // a proxy pointer, not the instance anymore.
+ instance = proxy;
+ }
+ }
+
+ return instance;
+ }
+
+ public virtual object RaiseUnWrapEvent(IHandler handler, object instance)
+ {
+ WrapDelegate eventDelegate = (WrapDelegate)m_events[ComponentUnWrapEvent];
+
+ // We can have a null wrapper here
+ InterceptedComponentWrapper wrapper = m_proxy2ComponentWrapper[instance] as InterceptedComponentWrapper;
+
+ if (wrapper != null)
+ {
+ m_proxy2ComponentWrapper.Remove(instance);
+ }
+
+ if (eventDelegate != null)
+ {
+ IComponentModel model = handler.ComponentModel;
+ String key = (String)m_service2Key[model.Service];
+
+ eventDelegate(model, key, handler, wrapper);
+ }
+
+ return wrapper != null ? wrapper.Instance : instance;
+ }
+
+ #endregion
+
+ protected virtual void RaiseDependencyEvent(Type service, IHandler handler)
+ {
+ DependencyListenerDelegate del = (DependencyListenerDelegate)m_dependencyToSatisfy[service];
+
+ if (del != null)
+ {
+ del(service, handler);
+ }
+ }
+
+ protected virtual void RaiseComponentRegistered(IComponentModel model, String key, IHandler handler)
+ {
+ ComponentDataDelegate eventDelegate = (ComponentDataDelegate)m_events[ComponentRegisteredEvent];
+
+ if (eventDelegate != null)
+ {
+ eventDelegate(model, key, handler);
+ }
+ }
+
+ protected virtual void RaiseComponentUnregistered(IComponentModel model, String key, IHandler handler)
+ {
+ ComponentDataDelegate eventDelegate = (ComponentDataDelegate)m_events[ComponentUnregisteredEvent];
+
+ if (eventDelegate != null)
+ {
+ eventDelegate(model, key, handler);
+ }
+ }
+
+ protected virtual void RaiseModelConstructed(IComponentModel model, String key)
+ {
+ ComponentModelDelegate eventDelegate = (ComponentModelDelegate)m_events[ComponentModelConstructedEvent];
+
+ if (eventDelegate != null)
+ {
+ eventDelegate(model, key);
+ }
+ }
+
+ public virtual IInterceptedComponentBuilder InterceptedComponentBuilder
+ {
+ get { return m_interceptedComponentBuilder; }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_interceptedComponentBuilder = value;
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public class InterceptedComponentWrapper : IInterceptedComponent
+ {
+ private IInterceptedComponentBuilder m_interceptedComponentBuilder;
+ private IInterceptedComponent m_delegate;
+ private object m_instance;
+ private Type m_service;
+
+ public InterceptedComponentWrapper(IInterceptedComponentBuilder interceptedComponentBuilder,
+ object instance, Type service)
+ {
+ m_interceptedComponentBuilder = interceptedComponentBuilder;
+ m_instance = instance;
+ m_service = service;
+ }
+
+ public object Instance
+ {
+ get { return m_instance; }
+ }
+
+ public object ProxiedInstance
+ {
+ get
+ {
+ EnsureDelegate();
+ return m_delegate.ProxiedInstance;
+ }
+ }
+
+ public void Add(IInterceptor interceptor)
+ {
+ EnsureDelegate();
+ m_delegate.Add(interceptor);
+ }
+
+ public IInterceptor InterceptorChain
+ {
+ get
+ {
+ EnsureDelegate();
+ return m_delegate.InterceptorChain;
+ }
+ }
+
+ public bool IsProxiedCreated
+ {
+ get { return m_delegate != null; }
+ }
+
+ private void EnsureDelegate()
+ {
+ if (m_delegate == null)
+ {
+ m_delegate = m_interceptedComponentBuilder.CreateInterceptedComponent(
+ m_instance, m_service);
+ }
+ }
+ }
+ }
+}
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 Thu Sep 2 12:19:13 2004
@@ -29,29 +29,15 @@
/// <summary>
/// Base implementation of <see cref="IKernel"/>
/// </summary>
- public class BaseKernel : IKernel, IDisposable
+ public class BaseKernel : AbstractKernelEvents, IKernel, IDisposable
{
- private static readonly object ComponentRegisteredEvent = new object();
- private static readonly object ComponentUnregisteredEvent = new object();
- private static readonly object ComponentWrapEvent = new object();
- private static readonly object ComponentUnWrapEvent = new object();
- private static readonly object ComponentReadyEvent = new object();
- private static readonly object ComponentReleasedEvent = new object();
- private static readonly object ComponentModelConstructedEvent = new object();
-
- protected EventHandlerList m_events;
-
protected IList m_componentsInstances = new ArrayList();
protected Hashtable m_key2Handler;
- protected Hashtable m_service2Key;
-
protected Hashtable m_subsystems;
- protected Hashtable m_dependencyToSatisfy;
-
- protected Hashtable m_proxy2ComponentWrapper;
+ protected Hashtable m_facilities;
protected IHandlerFactory m_handlerFactory;
@@ -59,23 +45,18 @@
protected ILifestyleManagerFactory m_lifestyleManagerFactory;
- protected IInterceptedComponentBuilder m_interceptedComponentBuilder;
/// <summary>
///
/// </summary>
- public BaseKernel()
+ public BaseKernel() : base()
{
- m_events = new EventHandlerList();
m_key2Handler = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
- m_service2Key = new Hashtable();
m_subsystems = new Hashtable();
- m_proxy2ComponentWrapper = new Hashtable();
+ m_facilities = new Hashtable();
m_handlerFactory = new SimpleHandlerFactory();
- m_dependencyToSatisfy = new Hashtable();
m_componentModelBuilder = new DefaultComponentModelBuilder(this);
m_lifestyleManagerFactory = new SimpleLifestyleManagerFactory();
- m_interceptedComponentBuilder = new DefaultInterceptedComponentBuilder();
InitializeSubsystems();
}
@@ -133,88 +114,51 @@
}
/// <summary>
- /// Pending
- /// </summary>
- /// <value></value>
- public event ComponentDataDelegate ComponentRegistered
- {
- add { m_events.AddHandler(ComponentRegisteredEvent, value); }
- remove { m_events.RemoveHandler(ComponentRegisteredEvent, value); }
- }
-
- /// <summary>
- /// Pending
+ /// Adds a subsystem.
/// </summary>
- /// <value></value>
- public event ComponentDataDelegate ComponentUnregistered
+ /// <param name="key">Name of this subsystem</param>
+ /// <param name="system">Subsystem implementation</param>
+ public void AddSubsystem(String key, IKernelSubsystem system)
{
- add { m_events.AddHandler(ComponentUnregisteredEvent, value); }
- remove { m_events.RemoveHandler(ComponentUnregisteredEvent, value); }
- }
+ AssertUtil.ArgumentNotNull(key, "key");
+ AssertUtil.ArgumentNotNull(system, "system");
- /// <summary>
- /// Pending
- /// </summary>
- /// <value></value>
- public event WrapDelegate ComponentWrap
- {
- add { m_events.AddHandler(ComponentWrapEvent, value); }
- remove { m_events.RemoveHandler(ComponentWrapEvent, value); }
- }
+ system.Init(this);
- /// <summary>
- /// Pending
- /// </summary>
- /// <value></value>
- public event UnWrapDelegate ComponentUnWrap
- {
- add { m_events.AddHandler(ComponentUnWrapEvent, value); }
- remove { m_events.RemoveHandler(ComponentUnWrapEvent, value); }
+ m_subsystems[ key ] = system;
}
/// <summary>
- /// Pending
+ ///
/// </summary>
- /// <value></value>
- public event ComponentInstanceDelegate ComponentReady
+ /// <param name="key"></param>
+ /// <param name="facility"></param>
+ public virtual void AddFacility(String key, IKernelFacility facility)
{
- add { m_events.AddHandler(ComponentReadyEvent, value); }
- remove { m_events.RemoveHandler(ComponentReadyEvent, value); }
- }
+ AssertUtil.ArgumentNotNull(key, "key");
+ AssertUtil.ArgumentNotNull(facility, "facility");
- /// <summary>
- /// Pending
- /// </summary>
- /// <value></value>
- public event ComponentInstanceDelegate ComponentReleased
- {
- add { m_events.AddHandler(ComponentReleasedEvent, value); }
- remove { m_events.RemoveHandler(ComponentReleasedEvent, value); }
- }
+ facility.Init(this);
- /// <summary>
- /// Pending
- /// </summary>
- /// <value></value>
- public event ComponentModelDelegate ComponentModelConstructed
- {
- add { m_events.AddHandler(ComponentModelConstructedEvent, value); }
- remove { m_events.RemoveHandler(ComponentModelConstructedEvent, value); }
+ m_facilities[ key ] = facility;
}
/// <summary>
- /// Adds a subsystem.
+ ///
/// </summary>
- /// <param name="key">Name of this subsystem</param>
- /// <param name="system">Subsystem implementation</param>
- public void AddSubsystem(String key, IKernelSubsystem system)
+ /// <param name="key"></param>
+ public virtual void RemoveFacility(String key)
{
AssertUtil.ArgumentNotNull(key, "key");
- AssertUtil.ArgumentNotNull(system, "system");
- system.Init(this);
+ IKernelFacility facility = m_facilities[ key ] as IKernelFacility;
- m_subsystems[ key ] = system;
+ if ( facility != null )
+ {
+ m_facilities.Remove(key);
+
+ facility.Terminate(this);
+ }
}
/// <summary>
@@ -257,7 +201,7 @@
/// <summary>
///
/// </summary>
- public IInterceptedComponentBuilder InterceptedComponentBuilder
+ public virtual IInterceptedComponentBuilder InterceptedComponentBuilder
{
get { return m_interceptedComponentBuilder; }
set
@@ -358,188 +302,6 @@
// AddSubsystem( KernelConstants.LOOKUP, new LookupCriteriaMatcher() );
// AddSubsystem( KernelConstants.EVENTS, new EventManager() );
}
-
- #region RaiseEvents
-
- protected virtual void RaiseDependencyEvent( Type service, IHandler handler )
- {
- DependencyListenerDelegate del = (DependencyListenerDelegate) m_dependencyToSatisfy[ service ];
-
- if ( del != null )
- {
- del( service, handler );
- }
- }
-
- protected virtual void RaiseComponentRegistered(IComponentModel model, String key, IHandler handler)
- {
- ComponentDataDelegate eventDelegate = (ComponentDataDelegate) m_events[ComponentRegisteredEvent];
-
- if (eventDelegate != null)
- {
- eventDelegate(model, key, handler);
- }
- }
-
- protected virtual void RaiseComponentUnregistered(IComponentModel model, String key, IHandler handler)
- {
- ComponentDataDelegate eventDelegate = (ComponentDataDelegate) m_events[ComponentUnregisteredEvent];
-
- if (eventDelegate != null)
- {
- eventDelegate(model, key, handler);
- }
- }
-
- protected virtual void RaiseModelConstructed(IComponentModel model, String key)
- {
- ComponentModelDelegate eventDelegate = (ComponentModelDelegate) m_events[ComponentModelConstructedEvent];
-
- if (eventDelegate != null)
- {
- eventDelegate(model, key);
- }
- }
-
- public virtual void RaiseComponentReadyEvent( IHandler handler, object instance )
- {
- ComponentInstanceDelegate eventDelegate = (ComponentInstanceDelegate) m_events[ComponentReadyEvent];
-
- if (eventDelegate != null)
- {
- IComponentModel model = handler.ComponentModel;
- String key = (String) m_service2Key[ model.Service ];
-
- eventDelegate(model, key, handler, instance);
- }
- }
-
- public virtual void RaiseComponentReleasedEvent( IHandler handler, object instance )
- {
- ComponentInstanceDelegate eventDelegate = (ComponentInstanceDelegate) m_events[ComponentReleasedEvent];
-
- if (eventDelegate != null)
- {
- IComponentModel model = handler.ComponentModel;
- String key = (String) m_service2Key[ model.Service ];
-
- eventDelegate(model, key, handler, instance);
- }
- }
-
- public virtual object RaiseWrapEvent( IHandler handler, object instance )
- {
- WrapDelegate eventDelegate = (WrapDelegate) m_events[ComponentWrapEvent];
-
- if (eventDelegate != null)
- {
- IComponentModel model = handler.ComponentModel;
- String key = (String) m_service2Key[ model.Service ];
- InterceptedComponentWrapper wrapper =
- new InterceptedComponentWrapper( m_interceptedComponentBuilder, instance, model.Service );
-
- eventDelegate(model, key, handler, wrapper);
-
- if (wrapper.IsProxiedCreated)
- {
- object proxy = wrapper.ProxiedInstance;
- m_proxy2ComponentWrapper[ proxy ] = wrapper;
-
- // From now on, the outside world will have
- // a proxy pointer, not the instance anymore.
- instance = proxy;
- }
- }
-
- return instance;
- }
-
- public virtual object RaiseUnWrapEvent( IHandler handler, object instance )
- {
- UnWrapDelegate eventDelegate = (UnWrapDelegate) m_events[ComponentUnWrapEvent];
-
- // We can have a null wrapper here
- InterceptedComponentWrapper wrapper = m_proxy2ComponentWrapper[ instance ] as InterceptedComponentWrapper;
-
- if (wrapper != null)
- {
- m_proxy2ComponentWrapper.Remove( instance );
- }
-
- if (eventDelegate != null)
- {
- IComponentModel model = handler.ComponentModel;
- String key = (String) m_service2Key[ model.Service ];
-
- eventDelegate(model, key, handler, wrapper);
- }
-
- return wrapper != null ? wrapper.Instance : instance;
- }
-
- /// <summary>
- ///
- /// </summary>
- internal class InterceptedComponentWrapper : IInterceptedComponent
- {
- private IInterceptedComponentBuilder m_interceptedComponentBuilder;
- private IInterceptedComponent m_delegate;
- private object m_instance;
- private Type m_service;
-
- public InterceptedComponentWrapper( IInterceptedComponentBuilder interceptedComponentBuilder,
- object instance, Type service )
- {
- m_interceptedComponentBuilder = interceptedComponentBuilder;
- m_instance = instance;
- m_service = service;
- }
-
- public object Instance
- {
- get { return m_instance; }
- }
-
- public object ProxiedInstance
- {
- get
- {
- EnsureDelegate();
- return m_delegate.ProxiedInstance;
- }
- }
-
- public void Add(IInterceptor interceptor)
- {
- EnsureDelegate();
- m_delegate.Add(interceptor);
- }
-
- public IInterceptor InterceptorChain
- {
- get
- {
- EnsureDelegate();
- return m_delegate.InterceptorChain;
- }
- }
-
- public bool IsProxiedCreated
- {
- get { return m_delegate != null; }
- }
-
- private void EnsureDelegate()
- {
- if (m_delegate == null)
- {
- m_delegate = m_interceptedComponentBuilder.CreateInterceptedComponent(
- m_instance, m_service );
- }
- }
- }
-
- #endregion
/// <summary>
/// Starts the component if the activation policy for
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernel.cs Thu Sep 2 12:19:13 2004
@@ -22,7 +22,8 @@
public delegate void DependencyListenerDelegate( Type service, IHandler handler );
/// <summary>
- /// Defines the Kernel service
+ /// Defines the Kernel contract and behavior.
+ /// <para></para>
/// </summary>
public interface IKernel : IKernelEvents
{
@@ -35,10 +36,10 @@
void AddComponent(String key, Type service, Type implementation);
/// <summary>
- ///
+ /// Removes a component from the kernel.
/// </summary>
- /// <param name="key"></param>
- void RemoveComponent(String key);
+ /// <param name="key">The unique key that identifies the component</param>
+ void RemoveComponent(String key);
/// <summary>
/// IComponentModel instance builder.
@@ -51,12 +52,16 @@
/// </summary>
IHandler this[String key] { get; }
- /// <summary>
- ///
+ void AddFacility( String key, IKernelFacility kernelFacility );
+
+ void RemoveFacility( String key );
+
+ /// <summary>
+ /// Returns a handler for the specified key and criteria.
/// </summary>
- /// <param name="key"></param>
- /// <param name="criteria"></param>
- /// <returns></returns>
+ /// <param name="key">The unique key that identifies the component</param>
+ /// <param name="criteria"></param>
+ /// <returns>Handler instance</returns>
IHandler GetHandler(String key, object criteria);
/// <summary>
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelEvents.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelEvents.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelEvents.cs Thu Sep 2 12:19:13 2004
@@ -19,84 +19,134 @@
using Apache.Avalon.Castle.MicroKernel.Model;
using Apache.Avalon.Castle.MicroKernel.Interceptor;
+ /// <summary>
+ /// Represents a delegate which holds basic information about a component.
+ /// </summary>
+ /// <param name="model">Component information</param>
+ /// <param name="key">Key which identifies the component</param>
+ /// <param name="handler">handler that holds this component and is capable of
+ /// creating an instance of it.
+ /// </param>
public delegate void ComponentDataDelegate( IComponentModel model, String key, IHandler handler );
- public delegate void WrapDelegate( IComponentModel model, String key, IHandler handler, IInterceptedComponent interceptedComponent );
-
- public delegate void UnWrapDelegate( IComponentModel model, String key, IHandler handler, IInterceptedComponent interceptedComponent );
+ /// <summary>
+ /// Represents a delegate which holds basic information about a component
+ /// and allows listeners to intercept (and proxy) the component instance.
+ /// </summary>
+ /// <param name="model">Component information</param>
+ /// <param name="key">Key which identifies the component</param>
+ /// <param name="handler">handler that holds this component and is capable of
+ /// creating an instance of it.
+ /// </param>
+ /// <param name="interceptedComponent">
+ /// Holds the component instance and its proxied version. If no interception is added
+ /// to the component, the proxied version is discarded and the kernel will work with
+ /// the component instance instead.
+ /// </param>
+ public delegate void WrapDelegate( IComponentModel model, String key, IHandler handler, IInterceptedComponent interceptedComponent );
- public delegate void ComponentInstanceDelegate( IComponentModel model, String key, IHandler handler, object instance );
+ /// <summary>
+ /// Represents a delegate which holds basic information about a component
+ /// and its instance.
+ /// </summary>
+ /// <param name="model">Component information</param>
+ /// <param name="key">Key which identifies the component</param>
+ /// <param name="handler">handler that holds this component and is capable of
+ /// creating an instance of it.
+ /// </param>
+ /// <param name="instance">Component instance</param>
+ public delegate void ComponentInstanceDelegate( IComponentModel model, String key, IHandler handler, object instance );
+ /// <summary>
+ /// Delegate which holds a group of component information.
+ /// </summary>
+ /// <param name="model">Component information</param>
+ /// <param name="key">Key which identifies the component</param>
public delegate void ComponentModelDelegate( IComponentModel model, String key );
/// <summary>
- ///
+ /// Kernel events contract.
/// </summary>
public interface IKernelEvents
{
/// <summary>
- ///
+ /// Event fired when a new component is registered
+ /// on the kernel.
/// </summary>
event ComponentDataDelegate ComponentRegistered;
/// <summary>
- ///
+ /// Event fired when a component is removed from the kernel.
/// </summary>
event ComponentDataDelegate ComponentUnregistered;
/// <summary>
- ///
+ /// Event fired when a component was instantiated
+ /// and its lifecycle phases was already performed.
+ /// Extensions can be applied by listening to this event
+ /// and proxying the component instance
/// </summary>
event WrapDelegate ComponentWrap;
/// <summary>
- ///
+ /// When the component is given back to the kernel
+ /// this event is fired. At the end, if a proxied instance was create
+ /// previously it will be discarded and the real component instance
+ /// will be available to the kernel, allowing it to performe
+ /// the final lifecycle phases.
/// </summary>
- event UnWrapDelegate ComponentUnWrap;
+ event WrapDelegate ComponentUnWrap;
- /// <summary>
- ///
+ /// <summary>
+ /// Event fired before the component is returned to the outside
+ /// world.
/// </summary>
event ComponentInstanceDelegate ComponentReady;
/// <summary>
- ///
+ /// Event fired when a component instance is given back to the
+ /// kernel.
/// </summary>
event ComponentInstanceDelegate ComponentReleased;
/// <summary>
- ///
+ /// Event fired when all information about a component was
+ /// successfully collected.
/// </summary>
event ComponentModelDelegate ComponentModelConstructed;
/// <summary>
- ///
+ /// Fires the ComponentWrap event. It should be called
+ /// only by the <see cref="IHandler"/> implementations.
/// </summary>
- /// <param name="instance"></param>
- /// <param name="handler"></param>
- /// <returns></returns>
+ /// <param name="instance">The component instance</param>
+ /// <param name="handler">The handler which owns the instance</param>
+ /// <returns>Returns the component instance or a proxy</returns>
object RaiseWrapEvent( IHandler handler, object instance );
/// <summary>
- ///
+ /// Fires the ComponentUnWrap event. It should be called
+ /// only by the <see cref="IHandler"/> implementations.
/// </summary>
- /// <param name="instance"></param>
- /// <param name="handler"></param>
- /// <returns></returns>
+ /// <param name="instance">The component instance (or a proxy)</param>
+ /// <param name="handler">The handler which owns the instance</param>
+ /// <returns>Should return the component instance, not the proxy</returns>
object RaiseUnWrapEvent( IHandler handler, object instance );
/// <summary>
- ///
+ /// Fires the ComponentReady event. It should be called
+ /// only by the <see cref="IHandler"/> implementation.
/// </summary>
- /// <param name="instance"></param>
- /// <param name="handler"></param>
- void RaiseComponentReadyEvent( IHandler handler, object instance );
+ /// <param name="instance">The component instance</param>
+ /// <param name="handler">The handler which owns the instance</param>
+ void RaiseComponentReadyEvent(IHandler handler, object instance);
/// <summary>
- ///
+ /// Fires the ComponentReleased event. It should be called
+ /// only by the <see cref="IHandler"/> implementation.
/// </summary>
- /// <param name="instance"></param>
- /// <param name="handler"></param>
+ /// <param name="instance">The component instance</param>
+ /// <param name="handler">The handler which owns the instance</param>
void RaiseComponentReleasedEvent( IHandler handler, object instance );
}
}
Added: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelFacility.cs
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelFacility.cs Thu Sep 2 12:19:13 2004
@@ -0,0 +1,42 @@
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Apache.Avalon.Castle.MicroKernel
+{
+ /// <summary>
+ /// The facility role is to increment the kernel functionality
+ /// by interception the kernel working - throught events - and
+ /// acting accordingly.
+ /// <para>For instance, a facility can expose your components as
+ /// managed components (managed extensions) by intercept
+ /// the components registration events. Other facility can intercept
+ /// the model construction and change the logger or configuration.
+ /// </para>
+ /// </summary>
+ public interface IKernelFacility
+ {
+ /// <summary>
+ /// Init the facility given it a chance to subscribe
+ /// to kernel events.
+ /// </summary>
+ /// <param name="kernel">Kernel instance</param>
+ void Init(IKernel kernel);
+
+ /// <summary>
+ /// Gives a chance to the facility to unsubscribe from the
+ /// events and do its proper clean up.
+ /// </summary>
+ void Terminate(IKernel kernel);
+ }
+}
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelSubsystem.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelSubsystem.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/IKernelSubsystem.cs Thu Sep 2 12:19:13 2004
@@ -1,4 +1,4 @@
- // Copyright 2004 The Apache Software Foundation
+// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,8 +15,19 @@
namespace Apache.Avalon.Castle.MicroKernel
{
/// <summary>
- /// Summary description for IKernelSubsystem.
+ /// Subsystems are used by the kernel to
+ /// expose information or implement some logic which may
+ /// increment the kernel functionality.
+ /// <para>
+ /// Tipical subsystems would be a configuration subsystem,
+ /// a logger subsystem and even a LookupCriteria subsystem.
+ /// </para>
/// </summary>
+ /// <remarks>
+ /// There are specific points in the default kernel implementation
+ /// which requests an specific subsystem. The subsystems keys may be
+ /// found in <see cref="KernelConstants"/>.
+ /// </remarks>
public interface IKernelSubsystem
{
void Init(IKernel kernel);
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/KernelConstants.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/KernelConstants.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/KernelConstants.cs Thu Sep 2 12:19:13 2004
@@ -1,49 +1,49 @@
-// Copyright 2004 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-namespace Apache.Avalon.Castle.MicroKernel
-{
- using System;
-
- /// <summary>
- /// Holds general Subsystem's names.
- /// </summary>
- public abstract class KernelConstants
- {
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Apache.Avalon.Castle.MicroKernel
+{
+ using System;
+
+ /// <summary>
+ /// Holds general Subsystem's names.
+ /// </summary>
+ public abstract class KernelConstants
+ {
/// <summary>
/// Identifies the ConfigurationManager subsystem.
- /// </summary>
- public static readonly String CONFIGURATION = "configuration";
-
+ /// </summary>
+ public static readonly String CONFIGURATION = "configuration";
+
/// <summary>
/// Identifies the LoggerManager subsystem.
- /// </summary>
- public static readonly String LOGGER = "logger";
-
+ /// </summary>
+ public static readonly String LOGGER = "logger";
+
/// <summary>
/// Identifies the ContextManager subsystem.
- /// </summary>
- public static readonly String CONTEXT = "context";
-
+ /// </summary>
+ public static readonly String CONTEXT = "context";
+
/// <summary>
/// Identifies the LookupCriteriaMatcher subsystem.
- /// </summary>
- public static readonly String LOOKUP = "lookup";
+ /// </summary>
+ public static readonly String LOOKUP = "lookup";
/// <summary>
/// Identifies the EventManager subsystem.
- /// </summary>
- public static readonly String EVENTS = "events";
- }
-}
+ /// </summary>
+ public static readonly String EVENTS = "events";
+ }
+}
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/BaseKernelTestCase.cs Thu Sep 2 12:19:13 2004
@@ -1,172 +1,179 @@
-// Copyright 2004 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-namespace Apache.Avalon.Castle.MicroKernel.Test
-{
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Apache.Avalon.Castle.MicroKernel.Test
+{
using System;
- using NUnit.Framework;
-
+ using NUnit.Framework;
+
using Apache.Avalon.Framework;
- using Apache.Avalon.Castle.MicroKernel;
- using Apache.Avalon.Castle.MicroKernel.Test.Components;
-
- /// <summary>
- /// Summary description for BaseKernelTestCase.
- /// </summary>
- [TestFixture]
- public class BaseKernelTestCase : Assertion
- {
- IKernel m_container;
-
- [SetUp]
+ using Apache.Avalon.Castle.MicroKernel;
+ using Apache.Avalon.Castle.MicroKernel.Test.Components;
+
+ /// <summary>
+ /// Summary description for BaseKernelTestCase.
+ /// </summary>
+ [TestFixture]
+ public class BaseKernelTestCase : Assertion
+ {
+ IKernel m_container;
+
+ [SetUp]
public void Init()
{
- m_container = new BaseKernel();
- }
-
- [TearDown]
+ m_container = new BaseKernel();
+ }
+
+ [TearDown]
public void Terminate()
{
- ContainerUtil.Dispose( m_container );
- }
-
- /// <summary>
- /// Just a simple Service resolution.
- /// No concerns or aspects involved.
- /// </summary>
- [Test]
- public void SimpleUsage()
- {
- m_container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- IHandler handler = m_container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- AssertNotNull( service );
-
- service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
-
- handler.Release( service );
- }
-
- [Test]
+ ContainerUtil.Dispose( m_container );
+ }
+
+ /// <summary>
+ /// Just a simple Service resolution.
+ /// No concerns or aspects involved.
+ /// </summary>
+ [Test]
+ public void SimpleUsage()
+ {
+ m_container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ IHandler handler = m_container[ "a" ];
+
+ IMailService service = handler.Resolve() as IMailService;
+
+ AssertNotNull( service );
+
+ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
+
+ handler.Release( service );
+ }
+
+ [Test]
public void InvalidComponent()
{
try
{
- m_container.AddComponent( "a", typeof(IMailService), typeof(String) );
- Fail("Should not allow a type which not implements the specified service.");
- }
+ m_container.AddComponent( "a", typeof(IMailService), typeof(String) );
+ Fail("Should not allow a type which not implements the specified service.");
+ }
catch(ArgumentException)
{
// Expected
- }
- }
-
- [Test]
- public void AddAndRemove()
- {
- m_container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- AssertNotNull( m_container.GetHandlerForService( typeof(IMailService) ) );
- AssertNotNull( m_container[ "a" ] );
-
- AssertNull( m_container.GetHandlerForService( typeof(IMailMarketingService) ) );
- AssertNull( m_container[ "b" ] );
-
- m_container.RemoveComponent( "a" );
-
- AssertNull( m_container.GetHandlerForService( typeof(IMailService) ) );
- AssertNull( m_container[ "a" ] );
- }
-
- [Test]
+ }
+ }
+
+ [Test]
+ public void AddAndRemove()
+ {
+ m_container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ AssertNotNull( m_container.GetHandlerForService( typeof(IMailService) ) );
+ AssertNotNull( m_container[ "a" ] );
+
+ AssertNull( m_container.GetHandlerForService( typeof(IMailMarketingService) ) );
+ AssertNull( m_container[ "b" ] );
+
+ m_container.RemoveComponent( "a" );
+
+ AssertNull( m_container.GetHandlerForService( typeof(IMailService) ) );
+ AssertNull( m_container[ "a" ] );
+ }
+
+ [Test]
public void StartableComponent()
{
SimpleStartableComponent.Constructed = false;
- m_container.AddComponent( "a", typeof(IStartableService), typeof(SimpleStartableComponent) );
-
- Assert( SimpleStartableComponent.Constructed );
- }
-
- [Test]
+ m_container.AddComponent( "a", typeof(IStartableService), typeof(SimpleStartableComponent) );
+
+ Assert( SimpleStartableComponent.Constructed );
+ }
+
+ [Test]
public void StartableComponentWithDependencies()
{
SimpleStartableComponent.Constructed = false;
- m_container.AddComponent( "a", typeof(IStartableService), typeof(SimpleStartableComponent2) );
-
- Assert( !SimpleStartableComponent.Constructed );
-
- m_container.AddComponent( "b", typeof(IMailService), typeof(SimpleMailService) );
-
- Assert( SimpleStartableComponent.Constructed );
- }
-
- [Test]
- public void ComponentDependingOnLogger()
- {
- m_container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailServiceWithLogger) );
-
- IHandler handler = m_container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- AssertNotNull( service );
-
- service.Send("hammett at apache dot org",
- "johndoe at yahoo dot org", "Aloha!", "What's up?");
-
- handler.Release( service );
- }
-
- /*
- [Test]
- public void FacilityLifecycle()
- {
- MockFacility facility = new MockFacility();
-
- m_container.RegisterFacility( facility );
-
- Assert( facility.OnInitCalled );
-
- m_container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailServiceWithLogger) );
-
- Assert( facility.ComponentAddedCalled );
-
- IHandler handler = m_container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- Assert( facility.ComponentCreatedCalled );
-
- AssertNotNull( service );
-
- service.Send("hammett at apache dot org",
- "johndoe at yahoo dot org", "Aloha!", "What's up?");
-
- handler.Release( service );
-
- Assert( facility.ComponentReleasedCalled );
- }
-
- public class MockFacility : IContainerFacility
- {
- }
- */
- }
-}
+ m_container.AddComponent( "a", typeof(IStartableService), typeof(SimpleStartableComponent2) );
+
+ Assert( !SimpleStartableComponent.Constructed );
+
+ m_container.AddComponent( "b", typeof(IMailService), typeof(SimpleMailService) );
+
+ Assert( SimpleStartableComponent.Constructed );
+ }
+
+ [Test]
+ public void ComponentDependingOnLogger()
+ {
+ m_container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailServiceWithLogger) );
+
+ IHandler handler = m_container[ "a" ];
+
+ IMailService service = handler.Resolve() as IMailService;
+
+ AssertNotNull( service );
+
+ service.Send("hammett at apache dot org",
+ "johndoe at yahoo dot org", "Aloha!", "What's up?");
+
+ handler.Release( service );
+ }
+
+ [Test]
+ public void FacilityLifecycle()
+ {
+ MockFacility facility = new MockFacility();
+ Assert(!facility.InitCalled);
+ Assert(!facility.TerminateCalled);
+
+ m_container.AddFacility( "mock", facility );
+ Assert(facility.InitCalled);
+ Assert(!facility.TerminateCalled);
+
+ m_container.RemoveFacility("mock");
+
+ Assert(facility.TerminateCalled);
+ }
+
+ public class MockFacility : IKernelFacility
+ {
+ private bool m_initCalled = false;
+ private bool m_terminateCalled = false;
+
+ public void Init(IKernel kernel)
+ {
+ m_initCalled = true;
+ }
+
+ public void Terminate(IKernel kernel)
+ {
+ m_terminateCalled = true;
+ }
+
+ public bool InitCalled
+ {
+ get { return m_initCalled; }
+ }
+
+ public bool TerminateCalled
+ {
+ get { return m_terminateCalled; }
+ }
+ }
+ }
+}
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/ComponentWrapperTestCase.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/ComponentWrapperTestCase.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/ComponentWrapperTestCase.cs Thu Sep 2 12:19:13 2004
@@ -33,21 +33,21 @@
[Test]
public void WrappingComponent()
{
- IKernel container = new BaseKernel();
-
- container.ComponentWrap += new WrapDelegate(ComponentWrap);
- container.ComponentUnWrap += new UnWrapDelegate(ComponentUnWrap);
-
- container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- IHandler handler = container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
+ IKernel container = new BaseKernel();
+
+ container.ComponentWrap += new WrapDelegate(ComponentWrap);
+ container.ComponentUnWrap += new WrapDelegate(ComponentUnWrap);
+
+ container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ IHandler handler = container[ "a" ];
+
+ IMailService service = handler.Resolve() as IMailService;
+
+ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
Assert( m_interceptor.InterceptorInvoked );
-
- handler.Release( service );
+
+ handler.Release( service );
}
private void ComponentWrap(IComponentModel model, string key, IHandler handler, IInterceptedComponent interceptedComponent)
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultAvalonKernelTestCase.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultAvalonKernelTestCase.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/DefaultAvalonKernelTestCase.cs Thu Sep 2 12:19:13 2004
@@ -1,153 +1,153 @@
using Apache.Avalon.Castle.MicroKernel.Handler;
-// Copyright 2004 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-namespace Apache.Avalon.Castle.MicroKernel.Test
-{
- using System;
-
- using NUnit.Framework;
-
- using Apache.Avalon.Castle.MicroKernel.Test.Components;
-
- /// <summary>
- /// Summary description for DefaultAvalonKernelTestCase.
- /// </summary>
- [TestFixture]
- public class DefaultAvalonKernelTestCase : Assertion
- {
- [Test]
- public void Creation()
- {
- IAvalonKernel kernel = new DefaultAvalonKernel();
- AssertNotNull(kernel);
- }
-
- /// <summary>
- /// Just a simple Service resolution.
- /// No concerns or aspects involved.
- /// </summary>
- [Test]
- public void SimpleUsage()
- {
- IAvalonKernel container = new DefaultAvalonKernel();
- container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- IHandler handler = container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- AssertNotNull( service );
-
- service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
-
- handler.Release( service );
- }
-
- [Test]
- public void SimpleAvalonComponent()
- {
- IAvalonKernel container = new DefaultAvalonKernel();
- container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService2) );
-
- IHandler handler = container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- AssertNotNull( service );
-
- AvalonMailService realInstance = (AvalonMailService) service;
-
- Assert( realInstance.initialized );
- Assert( realInstance.configured );
- Assert( !realInstance.disposed );
-
- service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
-
- handler.Release( service );
-
- Assert( realInstance.disposed );
- }
-
- [Test]
- public void AvalonComponentWithUnsatisfiedDependencies()
- {
- IAvalonKernel container = new DefaultAvalonKernel();
- container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService) );
-
- IHandler handler = container[ "b" ];
-
- try
- {
- ISpamService service = handler.Resolve() as ISpamService;
- Fail("Dependencies unsatisfied for this component. Resolve should fail.");
- }
+// Copyright 2004 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Apache.Avalon.Castle.MicroKernel.Test
+{
+ using System;
+
+ using NUnit.Framework;
+
+ using Apache.Avalon.Castle.MicroKernel.Test.Components;
+
+ /// <summary>
+ /// Summary description for DefaultAvalonKernelTestCase.
+ /// </summary>
+ [TestFixture]
+ public class DefaultAvalonKernelTestCase : Assertion
+ {
+ [Test]
+ public void Creation()
+ {
+ IAvalonKernel kernel = new DefaultAvalonKernel();
+ AssertNotNull(kernel);
+ }
+
+ /// <summary>
+ /// Just a simple Service resolution.
+ /// No concerns or aspects involved.
+ /// </summary>
+ [Test]
+ public void SimpleUsage()
+ {
+ IAvalonKernel container = new DefaultAvalonKernel();
+ container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ IHandler handler = container[ "a" ];
+
+ IMailService service = handler.Resolve() as IMailService;
+
+ AssertNotNull( service );
+
+ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
+
+ handler.Release( service );
+ }
+
+ [Test]
+ public void SimpleAvalonComponent()
+ {
+ IAvalonKernel container = new DefaultAvalonKernel();
+ container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService2) );
+
+ IHandler handler = container[ "a" ];
+
+ IMailService service = handler.Resolve() as IMailService;
+
+ AssertNotNull( service );
+
+ AvalonMailService realInstance = (AvalonMailService) service;
+
+ Assert( realInstance.initialized );
+ Assert( realInstance.configured );
+ Assert( !realInstance.disposed );
+
+ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
+
+ handler.Release( service );
+
+ Assert( realInstance.disposed );
+ }
+
+ [Test]
+ public void AvalonComponentWithUnsatisfiedDependencies()
+ {
+ IAvalonKernel container = new DefaultAvalonKernel();
+ container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService) );
+
+ IHandler handler = container[ "b" ];
+
+ try
+ {
+ ISpamService service = handler.Resolve() as ISpamService;
+ Fail("Dependencies unsatisfied for this component. Resolve should fail.");
+ }
catch(HandlerException)
{
// Expected.
- }
- }
-
- [Test]
- public void AvalonComponentWithDependencies()
- {
- IAvalonKernel container = new DefaultAvalonKernel();
- container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
- container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService) );
-
- IHandler handler = container[ "b" ];
-
- ISpamService service = handler.Resolve() as ISpamService;
- AssertNotNull( service );
-
- service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" );
-
- handler.Release( service );
- }
-
- [Test]
- public void HybridAvalonComponent()
- {
- IAvalonKernel container = new DefaultAvalonKernel();
- container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
- container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService2) );
-
- IHandler handler = container[ "b" ];
-
- ISpamService service = handler.Resolve() as ISpamService;
- AssertNotNull( service );
-
- service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" );
-
- handler.Release( service );
- }
-
- [Test]
- public void HybridAvalonComponentUsingSetters()
- {
- IAvalonKernel container = new DefaultAvalonKernel();
- container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
- container.AddComponent( "b", typeof(ISpamService2), typeof(AvalonSpamService3) );
-
- IHandler handler = container[ "b" ];
-
- ISpamService service = handler.Resolve() as ISpamService;
- AssertNotNull( service );
-
- service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" );
-
- handler.Release( service );
- }
- }
-}
+ }
+ }
+
+ [Test]
+ public void AvalonComponentWithDependencies()
+ {
+ IAvalonKernel container = new DefaultAvalonKernel();
+ container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
+ container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService) );
+
+ IHandler handler = container[ "b" ];
+
+ ISpamService service = handler.Resolve() as ISpamService;
+ AssertNotNull( service );
+
+ service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" );
+
+ handler.Release( service );
+ }
+
+ [Test]
+ public void HybridAvalonComponent()
+ {
+ IAvalonKernel container = new DefaultAvalonKernel();
+ container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
+ container.AddComponent( "b", typeof(ISpamService), typeof(AvalonSpamService2) );
+
+ IHandler handler = container[ "b" ];
+
+ ISpamService service = handler.Resolve() as ISpamService;
+ AssertNotNull( service );
+
+ service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" );
+
+ handler.Release( service );
+ }
+
+ [Test]
+ public void HybridAvalonComponentUsingSetters()
+ {
+ IAvalonKernel container = new DefaultAvalonKernel();
+ container.AddComponent( "a", typeof(IMailService), typeof(AvalonMailService) );
+ container.AddComponent( "b", typeof(ISpamService2), typeof(AvalonSpamService3) );
+
+ IHandler handler = container[ "b" ];
+
+ ISpamService service = handler.Resolve() as ISpamService;
+ AssertNotNull( service );
+
+ service.AnnoyPeople( "Work at home and earn a thousand dollars per second!" );
+
+ handler.Release( service );
+ }
+ }
+}
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/KernelEventsTestCase.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/KernelEventsTestCase.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/MicroKernelTest/KernelEventsTestCase.cs Thu Sep 2 12:19:13 2004
@@ -18,10 +18,10 @@
using NUnit.Framework;
- using Apache.Avalon.Castle.MicroKernel;
+ using Apache.Avalon.Castle.MicroKernel;
using Apache.Avalon.Castle.MicroKernel.Model;
using Apache.Avalon.Castle.MicroKernel.Interceptor;
- using Apache.Avalon.Castle.MicroKernel.Test.Components;
+ using Apache.Avalon.Castle.MicroKernel.Test.Components;
/// <summary>
/// Summary description for KernelEventsTestCase.
@@ -37,108 +37,108 @@
private bool m_ready = false;
private bool m_released = false;
- [Test]
- public void RegisteredAndUnregistered()
- {
- BaseKernel container = new BaseKernel();
-
- container.ComponentRegistered += new ComponentDataDelegate(Registered);
- container.ComponentUnregistered += new ComponentDataDelegate(Unregistered);
-
- Assert(!m_registered);
- Assert(!m_unregistered);
-
- container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- Assert(m_registered);
- Assert(!m_unregistered);
-
- m_registered = false;
-
- container.RemoveComponent( "a" );
-
- Assert(!m_registered);
- Assert(m_unregistered);
- }
-
- [Test]
- public void ModelConstructed()
- {
- BaseKernel container = new BaseKernel();
-
- container.ComponentModelConstructed += new ComponentModelDelegate(ComponentModelConstructed);
-
- Assert(!m_modelConstructed);
-
- container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- Assert(m_modelConstructed);
-
- m_modelConstructed = false;
-
- container.RemoveComponent( "a" );
-
- Assert(!m_modelConstructed);
- }
-
- [Test]
+ [Test]
+ public void RegisteredAndUnregistered()
+ {
+ BaseKernel container = new BaseKernel();
+
+ container.ComponentRegistered += new ComponentDataDelegate(Registered);
+ container.ComponentUnregistered += new ComponentDataDelegate(Unregistered);
+
+ Assert(!m_registered);
+ Assert(!m_unregistered);
+
+ container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ Assert(m_registered);
+ Assert(!m_unregistered);
+
+ m_registered = false;
+
+ container.RemoveComponent( "a" );
+
+ Assert(!m_registered);
+ Assert(m_unregistered);
+ }
+
+ [Test]
+ public void ModelConstructed()
+ {
+ BaseKernel container = new BaseKernel();
+
+ container.ComponentModelConstructed += new ComponentModelDelegate(ComponentModelConstructed);
+
+ Assert(!m_modelConstructed);
+
+ container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ Assert(m_modelConstructed);
+
+ m_modelConstructed = false;
+
+ container.RemoveComponent( "a" );
+
+ Assert(!m_modelConstructed);
+ }
+
+ [Test]
public void WrapAndUnwrap()
{
- BaseKernel container = new BaseKernel();
-
- container.ComponentWrap += new WrapDelegate(ComponentWrap);
- container.ComponentUnWrap += new UnWrapDelegate(ComponentUnWrap);
-
- container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- Assert(!m_wrap);
- Assert(!m_unwrap);
-
- IHandler handler = container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- Assert(m_wrap);
- Assert(!m_unwrap);
- m_wrap = false;
-
- service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
-
- handler.Release( service );
-
- Assert(!m_wrap);
- Assert(m_unwrap);
- }
-
- [Test]
+ BaseKernel container = new BaseKernel();
+
+ container.ComponentWrap += new WrapDelegate(ComponentWrap);
+ container.ComponentUnWrap += new WrapDelegate(ComponentUnWrap);
+
+ container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ Assert(!m_wrap);
+ Assert(!m_unwrap);
+
+ IHandler handler = container[ "a" ];
+
+ IMailService service = handler.Resolve() as IMailService;
+
+ Assert(m_wrap);
+ Assert(!m_unwrap);
+ m_wrap = false;
+
+ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
+
+ handler.Release( service );
+
+ Assert(!m_wrap);
+ Assert(m_unwrap);
+ }
+
+ [Test]
public void ReadyAndRelease()
{
- BaseKernel container = new BaseKernel();
-
- container.ComponentReady += new ComponentInstanceDelegate(ComponentReady);
- container.ComponentReleased += new ComponentInstanceDelegate(ComponentReleased);
-
- container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
-
- Assert(!m_ready);
- Assert(!m_released);
-
- IHandler handler = container[ "a" ];
-
- IMailService service = handler.Resolve() as IMailService;
-
- Assert(m_ready);
- Assert(!m_released);
- m_ready = false;
-
- service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
-
- handler.Release( service );
-
- Assert(!m_ready);
- Assert(m_released);
- }
-
+ BaseKernel container = new BaseKernel();
+
+ container.ComponentReady += new ComponentInstanceDelegate(ComponentReady);
+ container.ComponentReleased += new ComponentInstanceDelegate(ComponentReleased);
+
+ container.AddComponent( "a", typeof(IMailService), typeof(SimpleMailService) );
+
+ Assert(!m_ready);
+ Assert(!m_released);
+
+ IHandler handler = container[ "a" ];
+
+ IMailService service = handler.Resolve() as IMailService;
+
+ Assert(m_ready);
+ Assert(!m_released);
+ m_ready = false;
+
+ service.Send("hammett at apache dot org", "johndoe at yahoo dot org", "Aloha!", "What's up?");
+
+ handler.Release( service );
+
+ Assert(!m_ready);
+ Assert(m_released);
+ }
+
private void Registered(IComponentModel model, String key, IHandler handler)
{
AssertNotNull( model );
@@ -147,7 +147,7 @@
AssertEquals( "a", key );
m_registered = true;
- }
+ }
private void Unregistered(IComponentModel model, String key, IHandler handler)
{
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultComponentModel.cs Thu Sep 2 12:19:13 2004
@@ -77,36 +77,64 @@
public Lifestyle SupportedLifestyle
{
get { return m_lifestyle; }
- }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_lifestyle = value;
+ }
+ }
public Activation ActivationPolicy
{
get { return m_activation; }
- }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_activation = value;
+ }
+ }
public ILogger Logger
{
get { return m_logger; }
- set { m_logger = value; }
- }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_logger = value;
+ }
+ }
- public IConfiguration Configuration
+ public IConfiguration Configuration
{
get { return m_config; }
- set { m_config = value; }
- }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_config = value;
+ }
+ }
- public IContext Context
+ public IContext Context
{
get { return m_context; }
- }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_context = value;
+ }
+ }
- public IDependencyModel[] Dependencies
+ public IDependencyModel[] Dependencies
{
get { return m_dependencies; }
- }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_dependencies = value;
+ }
+ }
- public IConstructionModel ConstructionModel
+ public IConstructionModel ConstructionModel
{
get { return m_constructionModel; }
}
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultConstructionModel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultConstructionModel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultConstructionModel.cs Thu Sep 2 12:19:13 2004
@@ -44,18 +44,28 @@
get
{
return m_implementation;
- }
- }
+ }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_implementation = value;
+ }
+ }
public ConstructorInfo SelectedConstructor
{
get
{
return m_constructor;
- }
- }
-
- public PropertyInfo[] SelectedProperties
+ }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_constructor = value;
+ }
+ }
+
+ public PropertyInfo[] SelectedProperties
{
get
{
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultDependencyModel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultDependencyModel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/Default/DefaultDependencyModel.cs Thu Sep 2 12:19:13 2004
@@ -57,16 +57,26 @@
get
{
return m_key;
- }
- }
+ }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_key = value;
+ }
+ }
public bool Optional
{
get
{
return m_optional;
- }
- }
+ }
+ set
+ {
+ AssertUtil.ArgumentNotNull(value, "value");
+ m_optional = value;
+ }
+ }
#endregion
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IComponentModel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IComponentModel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IComponentModel.cs Thu Sep 2 12:19:13 2004
@@ -31,14 +31,14 @@
/// <summary>
/// Desired lifecycle
/// </summary>
- Lifestyle SupportedLifestyle { get; }
+ Lifestyle SupportedLifestyle { get; set; }
- /// <summary>
+ /// <summary>
/// Desired activation policy
/// </summary>
- Activation ActivationPolicy { get; }
+ Activation ActivationPolicy { get; set; }
- /// <summary>
+ /// <summary>
/// Service being exposed by the component
/// </summary>
Type Service { get; }
@@ -56,14 +56,14 @@
/// <summary>
/// Context for the component
/// </summary>
- IContext Context { get; }
+ IContext Context { get; set; }
- /// <summary>
+ /// <summary>
/// List of dependencies declared by the component
/// </summary>
- IDependencyModel[] Dependencies { get; }
+ IDependencyModel[] Dependencies { get; set; }
- /// <summary>
+ /// <summary>
/// Information to allow the correct construction
/// of the component
/// </summary>
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IConstructionModel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IConstructionModel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IConstructionModel.cs Thu Sep 2 12:19:13 2004
@@ -26,14 +26,14 @@
/// <summary>
/// Implementation type
/// </summary>
- Type Implementation { get; }
+ Type Implementation { get; set; }
- /// <summary>
+ /// <summary>
/// The best constructor selected.
/// </summary>
- ConstructorInfo SelectedConstructor { get; }
+ ConstructorInfo SelectedConstructor { get; set; }
- /// <summary>
+ /// <summary>
/// Properties that will be used to satisfy dependencies.
/// </summary>
PropertyInfo[] SelectedProperties { get; }
Modified: avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IDependencyModel.cs
==============================================================================
--- avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IDependencyModel.cs (original)
+++ avalon/trunk/central/laboratory/avalon-net/Castle/MicroKernel/Model/IDependencyModel.cs Thu Sep 2 12:19:13 2004
@@ -30,11 +30,11 @@
/// <summary>
/// Name that will be used to request this dependency.
/// </summary>
- String LookupKey { get; }
+ String LookupKey { get; set; }
- /// <summary>
+ /// <summary>
/// Is this dependency optional?
/// </summary>
- bool Optional { get; }
- }
+ bool Optional { get; set; }
+ }
}