Aspnetcore: ๋ณด๊ธฐ์— ์˜ต์…˜์„ ์–ด๋–ป๊ฒŒ ์ฃผ์ž…ํ•ฉ๋‹ˆ๊นŒ?

์— ๋งŒ๋“  2015๋…„ 09์›” 11์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: dotnet/aspnetcore

๊ตฌ์„ฑ์—์„œ ๊ฐ€์ ธ์˜ค๋Š” 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... ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋™์ผํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ๊ฒฝ์šฐ ์ฃผ์ž…ํ•  ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์™„์ „ํžˆ ๊ฒ€์ฆํ•ด์•ผ ํ•จ์„ ๊ธฐ์–ตํ•˜์‹ญ์‹œ์˜ค.

<strong i="6">@inject</strong> Microsoft.Extensions.Options.IOptions<AppOptions> AppOptionsAccessor

๋ชจ๋“  3 ๋Œ“๊ธ€

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

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰