avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: avalon-sandbox/csframework/src/test AttributesTestCase.cs
Date Fri, 01 Aug 2003 17:22:30 GMT
bloritsch    2003/08/01 10:22:30

  Modified:    csframework/src/cs Attributes.cs IServiceManager.cs
               csframework/src/test AttributesTestCase.cs
  Log:
  update the attributes and attribute testcases
  
  Revision  Changes    Path
  1.9       +132 -24   avalon-sandbox/csframework/src/cs/Attributes.cs
  
  Index: Attributes.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/csframework/src/cs/Attributes.cs,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Attributes.cs	1 Aug 2003 15:40:55 -0000	1.8
  +++ Attributes.cs	1 Aug 2003 17:22:30 -0000	1.9
  @@ -56,75 +56,183 @@
   	[AttributeUsage(AttributeTargets.Class,AllowMultiple=true)]
   	public sealed class AvalonService : Attribute
   	{
  -		private string m_name;
  +		private Type m_type;
   
   		///<summary>
   		///  Constructor to initialize the service's name.
   		///</summary>
  -		///<param name="name">The name of the service</param>
  -		public AvalonService(string name)
  +		///<param name="type">The type for the service</param>
  +        ///<exception cref="ArgumentException">If the "type" value is not an interface</exception>
  +        public AvalonService(Type type)
   		{
  -			m_name = name;
  +            if (!type.IsInterface)
  +            {
  +                throw new ArgumentException(
  +                    "The type passed in does not represent an interface",
  +                    "type" );
  +            }
  +
  +			m_type = type;
   		}
   
   		///<summary>
   		///  The name of the service
   		///</summary>
  -		public string Name
  +		public Type ServiceType
   		{
   			get
   			{
  -				return m_name;
  +				return m_type;
   			}
   		}
   	}
   
  +    /// <summary>
  +    /// An enumeration used to mark a dependency as optional or not.
  +    /// </summary>
  +	public enum Optional
  +	{
  +        /// <summary>
  +        /// Use "True" if the dependency is not required for the component
  +        /// to run properly.
  +        /// </summary>
  +		True,
  +        /// <summary>
  +        /// Use "False" if the component will not work without the dependnecy.
  +        /// </summary>
  +		False
  +	}
  +
   	///<summary>
   	///  Attribute to mark the dependencies for a component.
   	///</summary>
   	[AttributeUsage(AttributeTargets.Class,AllowMultiple=true)]
   	public sealed class AvalonDependency : Attribute
   	{
  +		private Type m_type;
  +		private bool m_optional;
   		private string m_name;
   
   		///<summary>
  -		///  Boolean property to see if this dependency is required or not.
  +		///  Constructor to initialize the dependency's name.
   		///</summary>
  -		public bool optional;
  -
  -		/// <summary>
  -		///   String prperty to use to look up the dependency from the
  -		///   <see cref="ILookupManager"/>
  -		/// </summary>
  -		public string key;
  +        ///<param name="type">The type for the dependency</param>
  +        ///<param name="key">The dependency's lookup key</param>
  +		///<param name="optional">Whether or not the dependency is optional</param>
  +		///<exception cref="ArgumentException">If the "type" value is not an interface</exception>
  +		public AvalonDependency(Type type, string key, Optional optional)
  +		{
  +            if (!type.IsInterface)
  +            {
  +                throw new ArgumentException(
  +                    "The type passed in does not represent an interface",
  +                    "type" );
  +            }
  +
  +            m_name = (null == key) ? type.Name : key;
  +			m_optional = (optional == Optional.True);
  +			m_type = type;
  +		}
   
   		///<summary>
  -		///  Constructor to initialize the dependency's name.
  +		///  The lookup name of the dependency
   		///</summary>
  -		///<param name="name">The dependency's name</param>
  -		public AvalonDependency(string name)
  +		public string Key
   		{
  -			m_name = name;
  -			optional = false;
  -			key = name;
  +			get
  +			{
  +				return m_name;
  +			}
   		}
   
   		///<summary>
  -		///  The name of the dependency
  +		///  Is this dependency optional?
   		///</summary>
  -		public string Name
  +		public bool IsOptional
   		{
   			get
   			{
  -				return m_name;
  +				return m_optional;
  +			}
  +		}
  +
  +		/// <summary>
  +		///   The dependency type
  +		/// </summary>
  +		public Type DependencyType
  +		{
  +			get
  +			{
  +				return m_type;
   			}
   		}
   	}
   
  +    /// <summary>
  +    /// Enumeration used to mark the component's lifestyle.
  +    /// </summary>
  +	public enum Lifestyle
  +	{
  +        /// <summary>
  +        /// Singleton components are instantiated once, and shared
  +        /// between all clients.
  +        /// </summary>
  +		Singleton,
  +        /// <summary>
  +        /// Thread components have a unique instance per thread.
  +        /// </summary>
  +		Thread,
  +        /// <summary>
  +        /// Pooled components have a unique instance per client,
  +        /// but they are managed in a pool.
  +        /// </summary>
  +		Pooled,
  +        /// <summary>
  +        /// Transient components are created on demand.
  +        /// </summary>
  +		Transient
  +	}
  +
   	///<summary>
   	///  Attribute used to mark a component as an Avalon component.
   	///</summary>
   	[AttributeUsage(AttributeTargets.Class,AllowMultiple=false)]
   	public sealed class AvalonComponent : Attribute
  -	{}
  +	{
  +		private Lifestyle m_lifestyle;
  +		private string m_name;
  +
  +        /// <summary>
  +        /// Marks a class as a component, providing a configuration name and preferred
lifestyle
  +        /// </summary>
  +        /// <param name="name">The name used for configuration elements</param>
  +        /// <param name="lifestyle">The lifestyle used for the component</param>
  +		public AvalonComponent( string name, Lifestyle lifestyle )
  +		{
  +			m_lifestyle = lifestyle;
  +			m_name = name;
  +		}
  +
  +        /// <summary>
  +        /// The configuration name assigned to this component.
  +        /// </summary>
  +		public string ConfigurationName
  +		{
  +			get
  +			{
  +				return m_name;
  +			}
  +		}
  +
  +        /// <summary>
  +        /// The lifestyle associated with the component
  +        /// </summary>
  +		public Lifestyle Lifestyle
  +		{
  +			get
  +			{
  +				return m_lifestyle;
  +			}
  +		}
  +	}
   }
  
  
  
  1.4       +8 -8      avalon-sandbox/csframework/src/cs/IServiceManager.cs
  
  Index: IServiceManager.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/csframework/src/cs/IServiceManager.cs,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IServiceManager.cs	1 Aug 2003 15:40:55 -0000	1.3
  +++ IServiceManager.cs	1 Aug 2003 17:22:30 -0000	1.4
  @@ -65,9 +65,9 @@
   	public interface ILookupManager
   	{
   		/// <summary>
  -		/// Gets the component associated with the given role.
  +		/// Gets the resource associated with the given key.
   		/// </summary>
  -		object this[string role] 
  +		object this[string key] 
   		{
   			get; 
   		}
  @@ -75,12 +75,12 @@
   		/// <summary>
   		/// Checks to see if a component exists for a role.
   		/// </summary>
  -		/// <param name="role">A String identifying the role to check.</param>
  -		/// <returns>True if the component exists; otherwise, false.</returns>
  -		bool Contains(string role);
  +		/// <param name="key">A String identifying the lookup name to check.</param>
  +		/// <returns>True if the resource exists; otherwise, false.</returns>
  +		bool Contains(string key);
   
   		/// <summary>
  -		/// Return the component when you are finished with it.
  +		/// Return the resource when you are finished with it.
   		/// This allows the <see cref="ILookupManager"/> to handle 
   		/// the End-Of-Life Lifecycle events associated with the component.
   		/// </summary>
  @@ -89,7 +89,7 @@
   		/// This is to allow easy use of the <see cref="ILookupManager"/> system without
   		/// having to trap Exceptions on a release.
   		/// </remarks>
  -		/// <param name="component">The component we are releasing.</param>
  -		void Release(object component);
  +		/// <param name="resource">The resource we are releasing.</param>
  +		void Release(object resource);
   	}
   }
  
  
  
  1.6       +19 -14    avalon-sandbox/csframework/src/test/AttributesTestCase.cs
  
  Index: AttributesTestCase.cs
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/csframework/src/test/AttributesTestCase.cs,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AttributesTestCase.cs	1 Aug 2003 15:40:56 -0000	1.5
  +++ AttributesTestCase.cs	1 Aug 2003 17:22:30 -0000	1.6
  @@ -58,31 +58,36 @@
   	[Test]
   	public void Service()
   	{
  -		string name = "Apache.AvalonFramework.AvalonAttributeTest";
  -		AvalonService service = new AvalonService( name );
  -		Assertion.AssertEquals( name, service.Name );
  +		Type type = typeof(IDisposable);
  +		AvalonService service = new AvalonService( type );
  +		Assertion.AssertEquals( type, service.ServiceType );
   	}
   
   	[Test]
   	public void Dependency()
   	{
  -		string name = "Apache.AvalonFramework.AvalonAttributeTest";
  -		AvalonDependency dependency = new AvalonDependency(name);
  -		Assertion.AssertEquals( name, dependency.Name );
  -		Assertion.AssertEquals( false, dependency.optional );
  +		string name="test";
  +		Type type = typeof(IDisposable);
  +		AvalonDependency dependency = new AvalonDependency(type,name,Optional.False);
  +		Assertion.AssertEquals( type, dependency.DependencyType );
  +		Assertion.AssertEquals( name, dependency.Key );
  +		Assertion.AssertEquals( false, dependency.IsOptional );
   
  -		dependency = new AvalonDependency(name);
  -		dependency.optional=true;
  -		dependency.key="attribute-test";
  -		Assertion.AssertEquals( name, dependency.Name );
  -		Assertion.AssertEquals( true, dependency.optional );
  -		Assertion.AssertEquals( "attribute-test", dependency.key );
  +		dependency = new AvalonDependency(type,null,Optional.True);
  +		Assertion.AssertEquals( type, dependency.DependencyType );
  +		Assertion.AssertEquals( type.Name, dependency.Key );
  +		Assertion.AssertEquals( true, dependency.IsOptional );
   	}
   
   	[Test]
   	public void Component()
   	{
  -		Assertion.AssertNotNull( new AvalonComponent() );
  +		string name="test";
  +		AvalonComponent component = new AvalonComponent( name, Lifestyle.Singleton );
  +		Assertion.AssertNotNull( component );
  +
  +		Assertion.AssertEquals( name, component.ConfigurationName );
  +		Assertion.AssertEquals( Lifestyle.Singleton, component.Lifestyle );
   	}
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message