2 /*****************************************************************************
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 ********************************************************************************/
23 /************************************************
25 *************************************************/
32 using System
.Collections
;
34 using Castle
.MVC
.States
;
37 namespace Castle
.MVC
.StatePersister
40 /// This class provides simple session-based state persister for Web applications.
42 public class SessionPersister
: IStatePersister
47 private IStateFactory _stateFactory
= null;
55 public SessionPersister()
59 #region IStatePersister Members
64 public IStateFactory StateFactory
66 get{ return _stateFactory;}
67 set{ _stateFactory = value; }
71 /// Saves state to the Session object.
73 /// <param name="state">The state to save.</param>
74 public void Save(IState state
)
76 // put State object directly into Session
77 HttpContext
.Current
.Session
[ BaseState
.SESSION_KEY
] = state
;
81 /// Loads the saved state.
83 /// <returns>The saved state</returns>
86 // pull State object directly out of Session
87 IState state
= HttpContext
.Current
.Session
[ BaseState
.SESSION_KEY
] as IState
;
90 state
= _stateFactory
.Create();
91 HttpContext
.Current
.Session
[ BaseState
.SESSION_KEY
] = state
;
100 /// <param name="state">The state to release.</param>
101 public void Release(IState state
)
103 HttpContext
.Current
.Session
.Remove( BaseState
.SESSION_KEY
);
104 _stateFactory
.Release(state
);