Added RedirectUsingNamedRoute
[castle.git] / Core / Castle.Core / Attributes / LifestyleAttributes.cs
blob9eafd91ed9330a53d9094f1622a961eecf019aab
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
15 namespace Castle.Core
17 using System;
19 /// <summary>
20 /// Base for Attributes that want to express lifestyle
21 /// chosen by the component.
22 /// </summary>
23 [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
24 public abstract class LifestyleAttribute : Attribute
26 private LifestyleType type;
28 /// <summary>
29 /// Initializes a new instance of the <see cref="LifestyleAttribute"/> class.
30 /// </summary>
31 /// <param name="type">The type.</param>
32 protected LifestyleAttribute(LifestyleType type)
34 this.type = type;
37 /// <summary>
38 /// Gets or sets the lifestyle.
39 /// </summary>
40 /// <value>The lifestyle.</value>
41 public LifestyleType Lifestyle
43 get { return type; }
44 set { type = value; }
48 /// <summary>
49 /// Indicates that the target components wants a
50 /// singleton lifestyle.
51 /// </summary>
52 [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
53 public class SingletonAttribute : LifestyleAttribute
55 /// <summary>
56 /// Initializes a new instance of the <see cref="SingletonAttribute"/> class.
57 /// </summary>
58 public SingletonAttribute() : base(LifestyleType.Singleton)
63 /// <summary>
64 /// Indicates that the target components wants a
65 /// transient lifestyle.
66 /// </summary>
67 [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
68 public class TransientAttribute : LifestyleAttribute
70 /// <summary>
71 /// Initializes a new instance of the <see cref="TransientAttribute"/> class.
72 /// </summary>
73 public TransientAttribute() : base(LifestyleType.Transient)
78 /// <summary>
79 /// Indicates that the target components wants a
80 /// per thread lifestyle.
81 /// </summary>
82 [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
83 public class PerThreadAttribute : LifestyleAttribute
85 /// <summary>
86 /// Initializes a new instance of the <see cref="PerThreadAttribute"/> class.
87 /// </summary>
88 public PerThreadAttribute() : base(LifestyleType.Thread)
93 /// <summary>
94 /// Indicates that the target components wants a
95 /// per web request lifestyle.
96 /// </summary>
97 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
98 public class PerWebRequestAttribute : LifestyleAttribute
100 public PerWebRequestAttribute() : base(LifestyleType.PerWebRequest)
105 /// <summary>
106 /// Indicates that the target components wants a
107 /// pooled lifestyle.
108 /// </summary>
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;
118 /// <summary>
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).
121 /// </summary>
122 public PooledAttribute() : this(Initial_PoolSize, Max_PoolSize)
126 /// <summary>
127 /// Initializes a new instance of the <see cref="PooledAttribute"/> class.
128 /// </summary>
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;
137 /// <summary>
138 /// Gets the initial size of the pool.
139 /// </summary>
140 /// <value>The initial size of the pool.</value>
141 public int InitialPoolSize
143 get { return initialPoolSize; }
146 /// <summary>
147 /// Gets the maximum pool size.
148 /// </summary>
149 /// <value>The size of the max pool.</value>
150 public int MaxPoolSize
152 get { return maxPoolSize; }
156 /// <summary>
157 /// Indicates that the target components wants a
158 /// custom lifestyle.
159 /// </summary>
160 [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
161 public class CustomLifestyleAttribute : LifestyleAttribute
163 private Type lifestyleHandler;
165 /// <summary>
166 /// Initializes a new instance of the <see cref="CustomLifestyleAttribute"/> class.
167 /// </summary>
168 /// <param name="lifestyleHandler">The lifestyle handler.</param>
169 public CustomLifestyleAttribute(Type lifestyleHandler) : base(LifestyleType.Custom)
171 this.lifestyleHandler = lifestyleHandler;
174 /// <summary>
175 /// Gets the type of the lifestyle handler.
176 /// </summary>
177 /// <value>The type of the lifestyle handler.</value>
178 public Type LifestyleHandlerType
180 get { return lifestyleHandler; }