I got a feature request that I should store something on session start. In the old ASP.NET Framework world it was easy because we had
Globbal.asax.cs and its
Session_Start event. The original answer to this question is here. But, as I prefer
overengineering modular architecture and Sitecore Helix principles I wanted to make it extensible without touching this Foundation piece of code. As you probably know we have Startup.cs instead of
DistributedSessionStore. To extend the Create method of the
DistributedSessionStore you can just simply inherit from its interface
As its seen above I have implemented a custom interface which contains all the actions I want to call on
Create. These 2 classes lays in the Foundation layer if you follow Sitecore Helix principles.
As a last but one, a
SessionExtensions (lays in the Foundation layer as well) implemented to put together the configuration of the session in one place:
As a last step call this method in the
ConfigureServices method and setup the application to use session – this lays in the Project layer.