c# - Lazy Singleton persisting across users -



c# - Lazy Singleton persisting across users -

i have lazy singleton used reference object web application.

it stores basic properties refrenenced throughout application:

public class context { public string username; public guid tenantid; public static context current { { homecoming lazy.value; } } private static readonly lazy<context> lazy = new lazy<context>(() => new context()); } //in action public static getsomethingforuser() { homecoming dataaccess.getsomethingforcurrentuser(context.current.username); }

the problem is, if user logs in , out context persisting across sessions.

this isn't unexpected, i'm not disposing it.

where should that? what's best method?

should on sign out?

public void signout() { context.dispose(); httpcontext.getowincontext().authentication.signout( openidconnectauthenticationdefaults.authenticationtype, cookieauthenticationdefaults.authenticationtype); }

in opinion, signout should event other classes can register , deed in response it.

the way using singleton seems okay me if have 1 active user @ time.

another solution removed signout problem, such has info within singleton should set within session itself.

c# session design-patterns singleton dispose

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -