Created
February 1, 2020 16:27
-
-
Save CoreProgramm/e54bdd1cff5bff75da5a239cc1b32665 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 HomeController : Controller | |
{ | |
private readonly ILogger<HomeController> _logger; | |
private IMobileService _mobileService; | |
public HomeController(ILogger<HomeController> logger, IMobileService mobileService) | |
{ | |
_logger = logger; | |
_mobileService = mobileService; | |
} | |
[HttpGet] | |
public ViewResult Create() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public IActionResult Create(Mobile mobile) | |
{ | |
if (ModelState.IsValid) | |
{ | |
Mobile newMobile = _mobileService.Add(mobile); | |
} | |
return View(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment