nothing4me
New Member
In my ASP.NET website I'm using a third-party library that uses a \[code\]Session\[/code\] object (with a \[code\]ISession\[/code\] interface). This is not to be confused with ASP.NET's Session. This Session class is time-expensive to create, so we want to create it once a user logs on and then persist this Session object through multiple HTTP requests. The object itself has an empty constructor, but it has a "Start" method that is passed user credentials as arguments, which then initializes the object to be user specific.In order to persist these user specific session objects over multiple HTTP requests, We have created a custom object that will maintain user Session objects in memory, the class looks like the following:\[code\]public class CustomSessionManagement{ public ISession CreateSession(string userName, string password) { // Code... } public void EndSession(string userName) { // Code... } public ISession GetSession(string userName) { // Code... }}\[/code\]Some of our service calls have a dependency on the ISession interface, as seen below:\[code\] public class Service { protected virtual ISession Session { get; set; } public Service(ISession session) { Session = session; } public void Method() { Session. // Code } }\[/code\]I would like to setup my Ninject bindings so that when a user logs on and their Session object is created (and is accessible through the CustomSessionManagement class), that the ISession dependency would be bound to the User's Session object.\[code\]i.e. Bind<ISession>.To<CustomSessionManagement.GetSession("username")>(); // ?????\[/code\]
- ASP.NET 4
- Ninject 3