๊ตฌ์ฑ์์ ๊ฐ์ ธ์ค๋ Azure CDN ๋์ ์ด ์์ต๋๋ค. ์ด ๋์ ์ ์ต์ ์ ๋ณด๊ดํ๊ณ ์ฌ์ฉํ ๋ณด๊ธฐ์ ์ฝ์ ํ๋ ค๊ณ ํฉ๋๋ค. ๋๋ ๋ถ์ด ์์ต๋๋ค ... .NET ๋ฌธ์ ๋ ๋ณด๊ธฐ ์ต์ ์ฃผ์ ์ ์ํ ๋งํฌ์ ์ฝ๋๋ฅผ ํ์ํ์ง ์์ผ๋ฉฐ Rick์ ๊ฒ์๋ฌผ ์ beta7์ฉ์ผ๋ก ์ ๋ฐ์ดํธ๋์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค. ์ ๋ dnx-coreclr-win-x64.1.0.0-beta7์ ์์ผ๋ฉฐ ์ด๊ฒ์ dnxcore50 ์ฑ์ ๋๋ค.
(์ฌ๊ธฐ์์ ๋ชจ๋ฒ ์ฌ๋ก๊ฐ ํผ๋๋จ: ์ด๊ฒ์ด ๋ชจ๋ธ์๋ ์ ์ฉ๋ฉ๋๊น?)
``` C#
๋ค์์คํ์ด์ค MyApp.Models
{
๊ณต๊ฐ ํด๋์ค AppOptions
{
๊ณต๊ฐ ๋ฌธ์์ด CDN { ๊ฐ์ ธ์ค๊ธฐ; ์ธํธ; }
}
}
#### Startup
``` c#
public class Startup
{
public IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
var configurationBuilder = new ConfigurationBuilder().AddEnvironmentVariables();
Configuration = configurationBuilder.Build();
Configuration["CDN"] = "az123456";
}
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<AppOptions>(Configuration);
services.AddSingleton(_ => Configuration);
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseErrorHandler("/error");
}
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
}
``` C#
๊ณต๊ฐ ํด๋์ค HomeController : ์ปจํธ๋กค๋ฌ
{
๊ณต๊ฐ HomeController(IOptions
{
์ต์
= optionsAccessor.Options;
}
AppOptions Options { get; }
[Route("/error")]
public IActionResult Script() => File("/wwwroot/error.htm", "text/html");
[HttpGet]
public IActionResult Index()
{
return View("index", Options);
}
}
#### Markup
If everything else above is ok, the markup part is unclear to me. How do I inject this?
- as a model with `<strong i="32">@model</strong> MyApp.Models.AppOptions`
- with inject `<strong i="33">@inject</strong> MyApp.Models.AppOptions AppOptions`
- is the problem with the reference in the `src=` ... how do I break the property lookup at the "CDN" before the period prior to "vo"?
``` html
<strong i="34">@inject</strong> MyApp.Models.AppOptions AppOptions
...
<body>
<!-- Error (squiggles) on "AppOptions" and complains it can't be found -->
<img src="http://@{AppOptions.CDN}.vo.msecnd.net/container/image.png" alt="Image from CDN">
<!-- Error (squiggles) on "vo" and complains its trying to lookup "vo" on the property -->
<img src="http://@AppOptions.CDN.vo.msecnd.net/container/image.png" alt="Image from CDN">
</body>
...
... <strong i="37">@model</strong> MyApp.Models.AppOptions
๋ฐ @{Model.CDN}.vo...
๋๋ @Model.CDN.vo...
๋ฅผ ์ฌ์ฉํ๋ฉด ๋์ผํ ๊ฒฐ๊ณผ๊ฐ ๋ํ๋ฉ๋๋ค.
IOptions
๋ DI ์ปจํ
์ด๋์ ์๋ ๊ฒ์ด๋ฏ๋ก $# <strong i="6">@inject</strong> IOptions<AppOptions> AppOptionsAccessor
Razor squiggles์ ๊ฒฝ์ฐ ์๋ชป๋ ๊ดํธ๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๋ ๋ฌธ์ ์ ๋๋ค.
<img src="http://@(AppOptionsAccessor.Options.CDN).vo.msecnd.net/container/image.png" alt="Image from CDN">
@pranavkm ์! ์ก์๋ค. ๊ฐ์ฌ ํด์.
๋ค๋ฅธ ์ฌ๋์ ๊ฒฝ์ฐ ์ฃผ์ ํ ์ธํฐํ์ด์ค๋ฅผ ์์ ํ ๊ฒ์ฆํด์ผ ํจ์ ๊ธฐ์ตํ์ญ์์ค.
<strong i="6">@inject</strong> Microsoft.Extensions.Options.IOptions<AppOptions> AppOptionsAccessor
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค๋ฅธ ์ฌ๋์ ๊ฒฝ์ฐ ์ฃผ์ ํ ์ธํฐํ์ด์ค๋ฅผ ์์ ํ ๊ฒ์ฆํด์ผ ํจ์ ๊ธฐ์ตํ์ญ์์ค.
<strong i="6">@inject</strong> Microsoft.Extensions.Options.IOptions<AppOptions> AppOptionsAccessor