1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
20 /// Base for Attributes that want to express lifestyle
21 /// chosen by the component.
23 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false)]
24 public abstract class LifestyleAttribute
: Attribute
26 private LifestyleType type
;
29 /// Initializes a new instance of the <see cref="LifestyleAttribute"/> class.
31 /// <param name="type">The type.</param>
32 protected LifestyleAttribute(LifestyleType type
)
38 /// Gets or sets the lifestyle.
40 /// <value>The lifestyle.</value>
41 public LifestyleType Lifestyle
49 /// Indicates that the target components wants a
50 /// singleton lifestyle.
52 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false)]
53 public class SingletonAttribute
: LifestyleAttribute
56 /// Initializes a new instance of the <see cref="SingletonAttribute"/> class.
58 public SingletonAttribute() : base(LifestyleType
.Singleton
)
64 /// Indicates that the target components wants a
65 /// transient lifestyle.
67 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false)]
68 public class TransientAttribute
: LifestyleAttribute
71 /// Initializes a new instance of the <see cref="TransientAttribute"/> class.
73 public TransientAttribute() : base(LifestyleType
.Transient
)
79 /// Indicates that the target components wants a
80 /// per thread lifestyle.
82 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false)]
83 public class PerThreadAttribute
: LifestyleAttribute
86 /// Initializes a new instance of the <see cref="PerThreadAttribute"/> class.
88 public PerThreadAttribute() : base(LifestyleType
.Thread
)
94 /// Indicates that the target components wants a
95 /// per web request lifestyle.
97 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
= false)]
98 public class PerWebRequestAttribute
: LifestyleAttribute
100 public PerWebRequestAttribute() : base(LifestyleType
.PerWebRequest
)
106 /// Indicates that the target components wants a
107 /// pooled lifestyle.
109 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false)]
110 public class PooledAttribute
: LifestyleAttribute
112 private static readonly int Initial_PoolSize
= 5;
113 private static readonly int Max_PoolSize
= 15;
115 private readonly int initialPoolSize
;
116 private readonly int maxPoolSize
;
119 /// Initializes a new instance of the <see cref="PooledAttribute"/> class
120 /// using the default initial pool size (5) and the max pool size (15).
122 public PooledAttribute() : this(Initial_PoolSize
, Max_PoolSize
)
127 /// Initializes a new instance of the <see cref="PooledAttribute"/> class.
129 /// <param name="initialPoolSize">Initial size of the pool.</param>
130 /// <param name="maxPoolSize">Max pool size.</param>
131 public PooledAttribute(int initialPoolSize
, int maxPoolSize
) : base(LifestyleType
.Pooled
)
133 this.initialPoolSize
= initialPoolSize
;
134 this.maxPoolSize
= maxPoolSize
;
138 /// Gets the initial size of the pool.
140 /// <value>The initial size of the pool.</value>
141 public int InitialPoolSize
143 get { return initialPoolSize; }
147 /// Gets the maximum pool size.
149 /// <value>The size of the max pool.</value>
150 public int MaxPoolSize
152 get { return maxPoolSize; }
157 /// Indicates that the target components wants a
158 /// custom lifestyle.
160 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false)]
161 public class CustomLifestyleAttribute
: LifestyleAttribute
163 private Type lifestyleHandler
;
166 /// Initializes a new instance of the <see cref="CustomLifestyleAttribute"/> class.
168 /// <param name="lifestyleHandler">The lifestyle handler.</param>
169 public CustomLifestyleAttribute(Type lifestyleHandler
) : base(LifestyleType
.Custom
)
171 this.lifestyleHandler
= lifestyleHandler
;
175 /// Gets the type of the lifestyle handler.
177 /// <value>The type of the lifestyle handler.</value>
178 public Type LifestyleHandlerType
180 get { return lifestyleHandler; }