I'm trying to use StructureMap in an asp.net MVC application instead of using HttpSession to store instances.
My simple test class:
public interface ICurrentSession
{
User User { get; set; }
}
public class CurrentSession : ICurrentSession
{
public User User { get; set; }
}
Here is the relevant registry code which is called in my bootstrapper:
x.For<ICurrentSession>().HttpContextScoped().Use<CurrentSession>();
And then after I authenticate a user, I call this:
var session = new CurrentSession {User = user};
ObjectFactory.Inject<ICurrentSession>(session);
However everytime I call ObjectFactory.GetInstance() it returns the same CurrentSession instance for each session (multiple browsers with multiple user's logged in). What am I doing wrong, or how can I inject a CurrentSession and have it scoped for each user/session logged in?