Ninject for a singleton session?

So, I am trying to introduce a user concept for my application and have my own set of custom login routines, etc., that work fine. In my module, I bind my IUserSession to my implementation and to InSingletonScope.

Now I suspect that this is so, and I was able to prove that it is not good to do this, if I try to log in with two users on the same site, I get only one data set.

If I implement MemberhipProvider, I avoid this restriction. I know that if I implement a membership provider, I don’t need to enter everything, but my login is not just a username and password, how to go about entering the system with additional data ??

+5
asp.net-mvc-3 ninject membership-provider
source share
1 answer

InSingletonScope is shared across the entire application, not limited to the user's session. None of this will change. You need to use something else, such as InRequestScope, but only for a general request ...

Try this site: http://iridescence.no/post/Session-Scoped-Bindings-With-Ninject-2.aspx

public static class NinjectSessionScopingExtention { public static void InSessionScope<T>(this IBindingInSyntax<T> parent) { parent.InScope(SessionScopeCallback); } private const string _sessionKey = "Ninject Session Scope Sync Root"; private static object SessionScopeCallback(IContext context) { if (HttpContext.Current.Session[_sessionKey] == null) { HttpContext.Current.Session[_sessionKey] = new object(); } return HttpContext.Current.Session[_sessionKey]; } } 
+11
source share

All Articles