Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Framework / Scopes / ThreadScopeAccessor.cs
blob7bd68de1cf7ee67722d6a8b835a1b380bd408ce1
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 /// Class to allow scopes to reach the implementation
21 /// of <see cref="IThreadScopeInfo"/>. Also implements
22 /// the <see cref="IThreadScopeInfo"/> delegating the calls to
23 /// the scope set.
24 /// </summary>
25 public sealed class ThreadScopeAccessor : IThreadScopeInfo
27 private static readonly ThreadScopeAccessor instance = new ThreadScopeAccessor();
29 private IThreadScopeInfo scopeInfo;
31 /// <summary>
32 /// Gets the single instance.
33 /// </summary>
34 /// <value>The instance.</value>
35 public static ThreadScopeAccessor Instance
37 get { return instance; }
40 /// <summary>
41 /// Gets or sets the scope info.
42 /// </summary>
43 /// <value>The scope info.</value>
44 public IThreadScopeInfo ScopeInfo
46 get { return scopeInfo; }
47 set { scopeInfo = value; }
50 #region IThreadScopeInfo Members
52 /// <summary>
53 /// Gets the current stack.
54 /// </summary>
55 /// <value>The current stack.</value>
56 public Stack CurrentStack
58 get { return scopeInfo.CurrentStack; }
61 /// <summary>
62 /// Gets the registered scope.
63 /// </summary>
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();
75 /// <summary>
76 /// Registers the scope.
77 /// </summary>
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);
89 /// <summary>
90 /// Unregister the scope.
91 /// </summary>
92 /// <param name="scope">The scope.</param>
93 public void UnRegisterScope(ISessionScope scope)
95 scopeInfo.UnRegisterScope(scope);
98 /// <summary>
99 /// Gets a value indicating whether this instance has initialized scope.
100 /// </summary>
101 /// <value>
102 /// <c>true</c> if this instance has initialized scope; otherwise, <c>false</c>.
103 /// </value>
104 public bool HasInitializedScope
106 get { return scopeInfo.HasInitializedScope; }
109 #endregion