Skip to content

Instantly share code, notes, and snippets.

@CoreProgramm
Last active February 1, 2020 17:30
Show Gist options
  • Save CoreProgramm/2a577516d94103279cbb6173e8158967 to your computer and use it in GitHub Desktop.
Save CoreProgramm/2a577516d94103279cbb6173e8158967 to your computer and use it in GitHub Desktop.
Difference between AddSingleton vs AddScoped vs AddTransient in asp.net core
public class MobileService:IMobileService
{
private List<Mobile> _mobileList;
public MobileService()
{
_mobileList = new List<Mobile>()
{
new Mobile() { id = 1, name = "Samsung", model="Note-10", price="70,000" },
new Mobile() { id = 2, name = "Nokia", model="S6", price="20,000" },
new Mobile() { id = 3, name = "Xiaomi", model="Note-8", price="21,999" }
};
}
public Mobile Add(Mobile mobile)
{
mobile.id = _mobileList.Max(e => e.id) + 1;
_mobileList.Add(mobile);
return mobile;
}
public IEnumerable<Mobile> GetAll()
{
return _mobileList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment