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 /// Class to allow scopes to reach the implementation
21 /// of <see cref="IThreadScopeInfo"/>. Also implements
22 /// the <see cref="IThreadScopeInfo"/> delegating the calls to
25 public sealed class ThreadScopeAccessor
: IThreadScopeInfo
27 private static readonly ThreadScopeAccessor instance
= new ThreadScopeAccessor();
29 private IThreadScopeInfo scopeInfo
;
32 /// Gets the single instance.
34 /// <value>The instance.</value>
35 public static ThreadScopeAccessor Instance
37 get { return instance; }
41 /// Gets or sets the scope info.
43 /// <value>The scope info.</value>
44 public IThreadScopeInfo ScopeInfo
46 get { return scopeInfo; }
47 set { scopeInfo = value; }
50 #region IThreadScopeInfo Members
53 /// Gets the current stack.
55 /// <value>The current stack.</value>
56 public Stack CurrentStack
58 get { return scopeInfo.CurrentStack; }
62 /// Gets the registered scope.
64 /// <returns></returns>
65 public ISessionScope
GetRegisteredScope()
67 if (scopeInfo
== null)
69 throw new ActiveRecordException(
70 "Can't get registered scope because the Active Record framework was not initialized.");
72 return scopeInfo
.GetRegisteredScope();
76 /// Registers the scope.
78 /// <param name="scope">The scope.</param>
79 public void RegisterScope(ISessionScope scope
)
81 if (scopeInfo
== null)
83 throw new ActiveRecordException("A scope tried to registered itself within the framework, " +
84 "but the Active Record was not initialized");
86 scopeInfo
.RegisterScope(scope
);
90 /// Unregister the scope.
92 /// <param name="scope">The scope.</param>
93 public void UnRegisterScope(ISessionScope scope
)
95 scopeInfo
.UnRegisterScope(scope
);
99 /// Gets a value indicating whether this instance has initialized scope.
102 /// <c>true</c> if this instance has initialized scope; otherwise, <c>false</c>.
104 public bool HasInitializedScope
106 get { return scopeInfo.HasInitializedScope; }