I have an asp.net web api 2 project in which I register a singleton LoginData
containerLocal.RegisterSingleton<ILoginData>(
() => new LoginData { LanguageCode = null, UserCode = null });
What I want to do is when a user log in to the app I register an instance of that Login data in my container
var loginData = AppContainer.Container.GetInstance<ILoginData>();
loginData.UserCode = userData.Username;
loginData.LanguageCode = "es";
and then, on whatever controller get that instance of user to perform any operation
my problem is that when I try to make a get request from 2 different browsers I get the last instance of Login data created in the app instead of the instance with the correct user
[Route("stock/menu")]
[HttpGet]
public async Task<IHttpActionResult> Menu()
{
var loginData = AppContainer.Container.GetInstance<ILoginData>();
return Ok(loginData);
}
example:
- Login in chrome browser with username 'foo'
- Make get request on InventarioMenu in chrome (gets LoginData with user 'foo')
- Login in firefox browser with username 'bar'
- Make get request on InventarioMenu in firefox (gets LoginData with user 'bar')
- Make get request on InventarioMenu in chrome (gets LoginData with user 'bar')