Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Framework / Scopes / AbstractThreadScopeInfo.cs
blobc81dc73e2a1b1769f0a6676ec5b095416abe0db8
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.ActiveRecord.Framework.Scopes
17 using System.Collections;
19 /// <summary>
20 /// Base <see cref="IThreadScopeInfo"/> implementation. It's up
21 /// to derived classes to provide a correct implementation
22 /// of <c>CurrentStack</c> only
23 /// </summary>
24 public abstract class AbstractThreadScopeInfo : IThreadScopeInfo
26 /// <summary>
27 /// Gets the current stack.
28 /// </summary>
29 /// <value>The current stack.</value>
30 public abstract Stack CurrentStack { get; }
32 /// <summary>
33 /// Registers the scope.
34 /// </summary>
35 /// <param name="scope">The scope.</param>
36 public void RegisterScope(ISessionScope scope)
38 CurrentStack.Push(scope);
41 /// <summary>
42 /// Gets the registered scope.
43 /// </summary>
44 /// <returns></returns>
45 public ISessionScope GetRegisteredScope()
47 Stack stack = CurrentStack;
49 if (stack.Count == 0)
51 return null;
53 else
55 return stack.Peek() as ISessionScope;
59 /// <summary>
60 /// Unregister the scope.
61 /// </summary>
62 /// <param name="scope">The scope.</param>
63 public void UnRegisterScope(ISessionScope scope)
65 if (GetRegisteredScope() != scope)
67 throw new ScopeMachineryException("Tried to unregister a scope that is not the active one");
70 CurrentStack.Pop();
73 /// <summary>
74 /// Gets a value indicating whether this instance has initialized scope.
75 /// </summary>
76 /// <value>
77 /// <c>true</c> if this instance has initialized scope; otherwise, <c>false</c>.
78 /// </value>
79 public bool HasInitializedScope
81 get { return GetRegisteredScope() != null; }