asp.net-core-mvc-2.0

Store / Retrieve ConnectionString from appSettings.json in ASP.net Core 2 MVC app

心已入冬 提交于 2019-11-27 04:54:43
I'm looking for the best practice way to store a connection string in appsettings.json in a .net Core 2 MVC app (like you do in web.config in MVC 5). I want to use Dapper not EF (I found many EF examples). Something like this: { "ConnectionStrings": { "myDatabase": "Server=.;Database=myDatabase;Trusted_Connection=true;" }, "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Warning" } } } Surely there are many examples online? Nothing I can find that is for .net core 2.0. Several things have changed between 1 and 2 and I want to ensure I'm using version 2 best practices. I've found

How to unit test ViewComponent.Invoke()?

左心房为你撑大大i 提交于 2019-11-26 17:24:05
问题 In ViewComponent object, HttpContext and User are read-only properties. How to unit test such a component? I'm using the MSTest Freamwork. The follow properties are used in my code Cookie Session User(System.Security.Principal) public ViewViewComponentResult Invoke() { var vm = new SummaryViewModel(); if (User.Identity is ClaimsIdentity identity && identity.IsAuthenticated) { vm.IsAuthenticated = true; vm.UserName = identity.Claims.FirstOrDefault(c => c.Type == "UserName").Value; vm.PhotoUrl

Store / Retrieve ConnectionString from appSettings.json in ASP.net Core 2 MVC app

这一生的挚爱 提交于 2019-11-26 11:25:22
问题 I\'m looking for the best practice way to store a connection string in appsettings.json in a .net Core 2 MVC app (like you do in web.config in MVC 5). I want to use Dapper not EF (I found many EF examples). Something like this: { \"ConnectionStrings\": { \"myDatabase\": \"Server=.;Database=myDatabase;Trusted_Connection=true;\" }, \"Logging\": { \"IncludeScopes\": false, \"LogLevel\": { \"Default\": \"Warning\" } } } Surely there are many examples online? Nothing I can find that is for .net