Single Responsibility Principle: Responsibility unknown
Posted
by
lurkerbelow
on Programmers
See other posts from Programmers
or by lurkerbelow
Published on 2012-07-07T15:24:02Z
Indexed on
2012/07/07
21:23 UTC
Read the original article
Hit count: 227
I store sessions in a SessionManager
. The session manager has a dependency to ISessionPersister
.
SessionManager
private readonly ISessionPersister sessionPersister;
public SessionManager(ISessionPersister sessionPersister)
{
this.sessionPersister = sessionPersister;
}
ISessionPersister
public interface ISessionPersister : IDisposable
{
void PersistSessions(Dictionary<string, ISession> sessions);
}
Q: If my application shuts down how / where do I call PersistSessions
? Who is responsible?
First Approach: Use Dispose in SessionManager
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this.sessionPersister != null && this.sessionMap != null && this.sessionMap.Count > 0)
{
this.sessionPersister.PersistSessions(this.sessionMap);
}
}
}
Is that the way to go or are there any better solutions?
© Programmers or respective owner