이번에 살펴볼 소스 코드는 ASP.NET Core 프레임워크에서 Web API를 만들고 서비스할 때 사용자 인증 중 하나인 Basic Authentication을 설정하는 코드이다. 개발환경은 Visual Studio 2019에서 .NET Core 3.1을 기본 프레임워크로 설정하였다. 프로젝트 생성은 VS2019에서 ‘새 프로젝트 구성 → ASP.NET Core 웹 애플리케이션 → 프로젝트 이름 입력 → Empty(비어있음) 프로젝트‘를 생성한다. 테스트한 클라이언트 툴은 Postman을 사용하였고 Authorization Type은 Basic Auth(Username, Password)를 선택하였다.
using BasicAuthCoreAPI.Middleware;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace BasicAuthCoreAPI
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); }
// 컨트롤러 [Route("api/xxx")] 일 때 Basic Auth
app.UseWhen(x => (x.Request.Path.StartsWithSegments("/api", System.StringComparison.OrdinalIgnoreCase)),
m => { m.UseMiddleware<AuthMiddleware>(); });
app.UseRouting();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
}
}
Blazor 컴포넌트 중 인기 있는 MatBlazor를 설치하고 사용하는 법을 간단한 CRUD 예제를 통하여 살펴본다. 사용한 예제는 Thumb IKR - Programming Examples Youtube 강좌이다. Blazor 강좌뿐 아니라 .NET과 관련한 좋은 강좌가 많이 있으므로 전체를 살펴보는 것을 추천한다. MatBlazor는 Form Controls, Navigation, Layout, Button & Indicators, Popups & Modals, Data Table 등으로 전반적인 컨트롤을 제공한다. 참고로 델파이와 닷넷 컴포넌트로 유명한 DevExpress는 Blazor 컴포넌트를 무료로 제공하고 있다(Demo).
<link href="_content/MatBlazor/dist/matBlazor.css" rel="stylesheet"/>
<script src="_content/MatBlazor/dist/matBlazor.js"></script>
public void ConfigureServices(IServiceCollection services)
{
//... 아래에 추가
services.AddScoped<HttpClient>();
}
A QThread object manages one thread of control within the program. QThreads begin executing in run(). By default, run() starts the event loop by calling exec() and runs a Qt event loop inside the thread. You can use worker objects by moving them to the thread using QObject::moveToThread().
The purpose of a QMutex is to protect an object, data structure or section of code so that only one thread can access it at a time (this is similar to the Java synchronized keyword). It is usually best to use a mutex with a QMutexLocker since this makes it easy to ensure that locking and unlocking are performed consistently.
아래의 소스는 Qt 프레임워크에서 Thread를 다루는 기본적인 예제이다. QMutex를 사용하여 Thread 동기화, Qt에서 Thread 사용을 위한 올바른 방법 그리고 UI(예, Label, Button 2개)에서 QThread를 사용하는 방법을 살펴본다.