1 // Copyright 2004-2008 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.
15 namespace Castle
.ActiveRecord
.Framework
.Scopes
17 using System
.Collections
;
20 /// Base <see cref="IThreadScopeInfo"/> implementation. It's up
21 /// to derived classes to provide a correct implementation
22 /// of <c>CurrentStack</c> only
24 public abstract class AbstractThreadScopeInfo
: IThreadScopeInfo
27 /// Gets the current stack.
29 /// <value>The current stack.</value>
30 public abstract Stack CurrentStack { get; }
33 /// Registers the scope.
35 /// <param name="scope">The scope.</param>
36 public void RegisterScope(ISessionScope scope
)
38 CurrentStack
.Push(scope
);
42 /// Gets the registered scope.
44 /// <returns></returns>
45 public ISessionScope
GetRegisteredScope()
47 Stack stack
= CurrentStack
;
55 return stack
.Peek() as ISessionScope
;
60 /// Unregister the scope.
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");
74 /// Gets a value indicating whether this instance has initialized scope.
77 /// <c>true</c> if this instance has initialized scope; otherwise, <c>false</c>.
79 public bool HasInitializedScope
81 get { return GetRegisteredScope() != null; }