Session context

50 views
Skip to first unread message

Germán Schuager

unread,
Dec 16, 2018, 9:41:55 AM12/16/18
to nhusers
Hi, I often have the requirement to store session related stuff known at session creation that need to be used at some other point in time (for example in event listeners, which are singletons).
I solved this case in some places using basically a Dictionary<ISession, SessionContext> (SessionContext is another dictionary), but always thought that it would be very useful if ISession would already contain an Items bag for example... is there anything like that?

Gunnar Liljas

unread,
Dec 16, 2018, 10:16:04 AM12/16/18
to nhu...@googlegroups.com
Hi,

There are indeed cases where such a thing would be nice, but currently
there is no such thing. What you're already doing is probably the best
workaround, but I would use WeakReferences or a ConditionalWeakTable,
so that the dictionary doesn't hold references to discarded sessions.

/G

Den sön 16 dec. 2018 kl 15:42 skrev Germán Schuager <gsch...@gmail.com>:
>
> Hi, I often have the requirement to store session related stuff known at session creation that need to be used at some other point in time (for example in event listeners, which are singletons).
> I solved this case in some places using basically a Dictionary<ISession, SessionContext> (SessionContext is another dictionary), but always thought that it would be very useful if ISession would already contain an Items bag for example... is there anything like that?
>
> --
> You received this message because you are subscribed to the Google Groups "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
> To post to this group, send email to nhu...@googlegroups.com.
> Visit this group at https://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.

Germán Schuager

unread,
Dec 16, 2018, 12:11:16 PM12/16/18
to nhu...@googlegroups.com
Thanks for the tip! I'm already ensuring that things get cleaned up correctly, but ConditionalWeakTable seems to better fit this use case, I didn't know about it.

Would this feature be something worth adding to NH? Maybe even disposing IDisposable items on session dispose. Would you accept a PR?


You received this message because you are subscribed to a topic in the Google Groups "nhusers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nhusers/fySOrgnCynU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nhusers+u...@googlegroups.com.

Frédéric Delaporte

unread,
Dec 28, 2018, 5:39:02 PM12/28/18
to nhusers
Why not, but as this implies a change in the ISession/IStatelessSession interfaces (any change in an interface is binary breaking, even just adding things), it could be merged only in 6.0, unless done via extension methods instead at first.
About disposing things which have been supplied to the session by users, I dislike the idea. It may not be right for all use cases. Better leave that to who has created them.
Reply all
Reply to author
Forward
0 new messages