Single Responsibility Principle: Responsibility unknown [closed]
https://softwareengineering.stackexchange.com/questions/155948
-
04-11-2019 - |
Pergunta
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?
Nenhuma solução correta
Licenciado em: CC-BY-SA com atribuição
Não afiliado a softwareengineering.stackexchange