My app flow is as follows (simplified for clarity):
- User GETs a page from “/page1”
- User performs actions on the page (adds text, clicks, etc..), while Signalr communicates this data to the server, which performs heavy calculations in the background, and the results of those are returned to the page (lets call those “X”).
- When the user is finished with the page, he clicks a link to “/page2”, that is returned by Nancy. This page is built using a Model that is dependent on X.
So, how do I build that Model based on X? How can signalr write to the user session in a way that Nancy can pick up on?
(I’m looking for a “clean” way)
Pending formal integration of Signalr & Nancy, this is what I came with. Basically, I share an IOC container between the two, and use an object (singleton lifetime) that maps users to state.
How to share an IOC container using the built in TinyIOC:
Extend Signalr’s DefaultDependencyResolver
Replace Signalr’s default DependencyResolver with our new one
Add IUserToStateMap as a dependency in your hubs and Nancy modules
What I would really want, is a way to easily share state between the two based on the connection ID or something like that, but in the meantime this solution works for me.