I'm learning Ninject and doing a trial (thur a web api project).
I wrote a controller, which will call a repository and update elements in a data source
I have a class which acts as a data source (to kee things simple)
public class UserDb
{
private readonly List<UserModel> _listUsers;
public UserDb()
{
_listUsers = new List<UserModel>();
_listUsers.Add(new UserModel { UserId = "A123", CreditRemaining = 10.00, LastModified = DateTimeOffset.Now });
_listUsers.Add(new UserModel { UserId = "ABC1", CreditRemaining = 20.35, LastModified = DateTimeOffset.Now });
}
public List<UserModel> Users => _listUsers;
}
In my Ninjectwebcommon file I create dependencies in following way
kernel.Bind<IUserCardDetailsRepository>().To<UserCardDetailsRepository>().InRequestScope();
kernel.Bind<LockingObject>().ToSelf().InSingletonScope();
kernel.Bind<UserDb>().ToSelf().InSingletonScope();
Now for every request I make to the controller, it creates a new instance of UserDb, instead of using the one already created.
I thought InSingletonScope creates it once and distributes it, so the state of the object persists? What am I missing?