Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 224aa20

Browse files
Names configuration in asp.net core
1 parent 81c9687 commit 224aa20

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

‎Webgentle.BookStore/Webgentle.BookStore/Controllers/HomeController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ namespace Webgentle.BookStore.Controllers
1313
public class HomeController : Controller
1414
{
1515
private readonly NewBookAlertConfig _newBookAlertconfiguration;
16+
private readonly NewBookAlertConfig _thirdPartyBookconfiguration;
1617
private readonly IMessageRepository _messageRepository;
1718

1819
public HomeController(IOptionsSnapshot<NewBookAlertConfig> newBookAlertconfiguration, IMessageRepository messageRepository)
1920
{
20-
_newBookAlertconfiguration = newBookAlertconfiguration.Value;
21+
_newBookAlertconfiguration = newBookAlertconfiguration.Get("InternalBook");
22+
_thirdPartyBookconfiguration = newBookAlertconfiguration.Get("ThirdPartyBook");
2123
_messageRepository = messageRepository;
2224
}
2325

2426
public ViewResult Index()
2527
{
2628
bool isDisplay = _newBookAlertconfiguration.DisplayNewBookAlert;
29+
bool isDisplay1 = _thirdPartyBookconfiguration.DisplayNewBookAlert;
2730

28-
var value = _messageRepository.GetName();
31+
//var value = _messageRepository.GetName();
2932

3033
//var newBook = configuration.GetSection("NewBookAlert");
3134
//var result = newBook.GetValue<bool>("DisplayNewBookAlert");

‎Webgentle.BookStore/Webgentle.BookStore/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public void ConfigureServices(IServiceCollection services)
4747
services.AddScoped<ILanguageRepository, LanguageRepository>();
4848
services.AddSingleton<IMessageRepository, MessageRepository>();
4949

50-
services.Configure<NewBookAlertConfig>(_configuration.GetSection("NewBookAlert"));
50+
services.Configure<NewBookAlertConfig>("InternalBook",_configuration.GetSection("NewBookAlert"));
51+
services.Configure<NewBookAlertConfig>("ThirdPartyBook",_configuration.GetSection("ThirdPartyBook"));
5152
}
5253

5354
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

‎Webgentle.BookStore/Webgentle.BookStore/Views/Shared/_header.cshtml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
@inject IConfiguration _configuration
33
@inject Microsoft.Extensions.Options.IOptionsSnapshot<NewBookAlertConfig> _newBookAlertconfiguration
44
@{
5-
var newBookAlertconfiguration = _newBookAlertconfiguration.Value;
5+
var newBookAlertconfiguration = _newBookAlertconfiguration.Get("InternalBook");
6+
var thirdPartyBookAlertconfiguration = _newBookAlertconfiguration.Get("ThirdPartyBook");
67
}
78

89
<header>
@@ -51,4 +52,11 @@
5152
</div>
5253
}
5354

55+
@if (thirdPartyBookAlertconfiguration.DisplayNewBookAlert)
56+
{
57+
<div class="alert alert-info" role="alert">
58+
@thirdPartyBookAlertconfiguration.BookName
59+
</div>
60+
}
61+
5462
</header>

‎Webgentle.BookStore/Webgentle.BookStore/appsettings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
"AppName": "Book store App",
1414

1515
"NewBookAlert": {
16-
"DisplayNewBookAlert": true,
17-
"BookName": "A new book XYZ-updated.pdf is released"
16+
"DisplayNewBookAlert": false,
17+
"BookName": "A new book XYZ-updated.pdf is released 11111333"
18+
},
19+
"ThirdPartyBook": {
20+
"DisplayNewBookAlert": false,
21+
"BookName": "This is third party book 1111"
1822
},
1923
"infoObj": {
2024
"key1": "key 1 value",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /