@manhng

Welcome to my blog!

Deploy ASP.NET Core 5.0

March 16, 2021 00:07

Deploy ASP.NET Core 5.0 (edit)

  • Kestrel web server
  • Install the IIS
  • Install the ASP.NET Core Hosting Bundle
    • .NET Core Runtime
    • ASP.NET Core Module

Kestrel web server

Kestrel là một HTTP web server mã nguồn mở (open source), đa nền tảng (cross-platform), hướng sự kiện (event-driven) và bất đồng bộ (asynchronous I/O). Nó được phát triển để chạy ứng dụng ASP.NET Core trên bất cứ nền tảng nào. Nó được thêm vào mặc định trong ứng dụng ASP.NET Core.

https://tedu.com.vn/lap-trinh-aspnet-core/kestrel-web-server-danh-cho-aspnet-core-212.html

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-5.0

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-5.0/

https://weblog.west-wind.com/posts/2016/jun/06/publishing-and-running-aspnet-core-applications-with-iis/

https://www.c-sharpcorner.com/article/how-to-deploy-asp-net-core-5-0-application-in-windows-server-iis/

https://www.codeproject.com/Articles/5258320/Deploy-ASP-NET-Core-Web-API-on-IIS/

https://arghya.xyz/articles/aspnetcore-on-windows-iis/

Configuration & Dependency Injection in ASP.NET Core

  • IOptions<TOptions>
  • IOptionsSnapshot<TOptions>
  • IOptionsMonitor<TOptions>
  • ...
  • IConfiguration
  • ...
  • Transient: Creted each time they are requested
  • Scoped: Created once per http request
  • Singleton: Created once per lifetime of application

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-5.0

https://andrewlock.net/creating-singleton-named-options-with-ioptionsmonitor/

https://xuanthulab.net/asp-net-core-cau-hinh-ung-dung-web-appsettings-json-va-inject-option-cho-cac-dich-vu-c-csharp.html

https://arghya.xyz/articles/practical-configuration-and-di-in-aspnet-core/

//Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    //with framework provided extension methods
    services.AddDbContext<MyDbContext>(opt => opt.UseInMemoryDatabase("MyDbName"));
    services.AddMvc(); //inject all services related to MVC
    //simple scoped service registration
    services.AddScoped<IRepository, Repository>();
    services.AddTransient<ISomeService, SomeService>();
    services.AddSingleton<IConfigBuilder, FileConfigBuilder>();
    //any type that needs injection/to be injected
    services.AddScoped<JustAnotherEntity>();
    //instance registration example, sp is IServiceProvider
    services.AddTransient<MyService>(sp => new MyService(
        "Some string argument",
        sp.GetService<ISomeService>()));
}

Categories

Recent posts