Skip to content

Commit

Permalink
Пример внедрения типизированной конфигурации в представлении
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Kotsiuban committed Aug 6, 2015
1 parent b18d16d commit 88dc1e7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/aspnet5/Properties/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace aspnet5
{
/// <summary>
/// Типизированные настройки
/// </summary>
public class AppSettings
{
public string SiteTitle { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/aspnet5/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
public void ConfigureServices(IServiceCollection services)
{
// Add Application settings to the services container.
// добавляем в кофигурацию типизированные настройки из конфиг файла
services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
services.Configure<DataSettings>(Configuration.GetConfigurationSection("Data:DefaultConnection"));

Expand Down
2 changes: 2 additions & 0 deletions src/aspnet5/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using aspnet5
@*регистрируем зависимость*@
@inject IOptions<AppSettings> AppSettings
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -32,6 +33,7 @@
<span class="icon-bar"></span>
</button>
<a asp-controller="Home" asp-action="Index" class="navbar-brand">
@*достаем значение в представлении из конфигурации*@
@AppSettings.Options.SiteTitle
</a>
</div>
Expand Down

0 comments on commit 88dc1e7

Please sign in to comment.