Last active
February 1, 2020 17:30
-
-
Save CoreProgramm/2a577516d94103279cbb6173e8158967 to your computer and use it in GitHub Desktop.
Difference between AddSingleton vs AddScoped vs AddTransient in asp.net core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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