# IOptions的使用 ###### tags: `.net core` `appsetting` `IOption` ### DI ` services.Configure<InboxConfig>(Configuration.GetSection("InboxConfig"));` ### config class 內容屬性需對應appsetting裡面的屬性 ``` public class InboxConfig { public string BaseUrl { get; set; } } ``` ### appsetting.json ``` "InboxConfig": { "BaseUrl": "https://domain.com" } ``` ### View中使用IOption ``` @using Microsoft.Extensions.Options @using BusinessSecretAndJobTransferApply.Models.OptionValue @inject IOptions<InboxConfig> inboxOption @{ var inboxConfig = inboxOption.Value; // Value 才是我們要使用的實際資料 } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up