애플리케이션 Use Cases 정의
Use cases๋ ๋น์ฆ๋์ค ์๋๋ฅผ ์คํ ๊ฐ๋ฅํ ์ํํธ์จ์ด๋ก ๋ฐ๊พธ๋ ์ ํ๋ฆฌ์ผ์ด์
๊ณ์ธต์ ์ง์
์ ์
๋๋ค. Lino์์๋ Application/UseCases์ ์์นํ๋ฉฐ ํ๋ก์ ํธ์ ์ด์ ๋จ๊ณ์์ ์ ์ํ ์ํฐํฐ, aggregates, ์ด๊ฑฐํ, ๋ชจ๋, ์๋น์ค๋ฅผ ์ค์ฌ์ผ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค.
Lino๋ CQRS ์งํฅ ๊ตฌ์กฐ๋ฅผ ๋ฐ๋ฆ ๋๋ค. Commands๋ ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ์์ ์ ๋ํ๋ด๊ณ , Queries๋ ๋ฐ์ดํฐ๋ฅผ ์ฝ๋ ์์ ์ ๋ํ๋ ๋๋ค. ์ด ๋ถ๋ฆฌ๋ ์ฐ๊ธฐ ๊ท์น, read models, validation, tracing, logging, response contracts๋ฅผ ๋ช ์์ ์ผ๋ก ์ ์งํ๊ณ ๋ ์ฝ๊ฒ ๊ด๋ฆฌํ๊ฒ ํด ์ค๋๋ค.
Result Pattern์ ์ฑ๊ณต, ์คํจ, ์ค๋ฅ ๋ฉ์์ง, ๊ฒฐ๊ณผ ๋ฐ์ดํฐ๋ฅผ ์บก์ํํ์ฌ ์์
์ ๋ฐํ๊ฐ์ ํ์คํํฉ๋๋ค. ์์๋๋ ๋น์ฆ๋์ค ํ๋ฆ์ ์์ธ๋ฅผ ์ฌ์ฉํ๋ ๋์ handler๋ ์ํฉ์ ๋ฐ๋ผ ๊ฐ, ์ค๋ฅ ๋๋ no-content๋ฅผ ๋ด์ Result ๋๋ Result<T>๋ฅผ ๋ฐํํฉ๋๋ค.
CLI๋ use case์ ์ด๊ธฐ ํ์ผ์ ์์ฑํ์ง๋ง, ์์ฑ๋ ์ฝ๋๋ ๋๋ฉ์ธ ๋ถ์์ ๋์ฒดํ์ง ์์ต๋๋ค. ๊ฐ๋ฐ์๋ ์ฌ์ ํ handler๋ฅผ ๊ฒํ ํ๊ณ , ์ ํ๋ ์์ฑ์ ํ์ธํ๊ณ , ๋น์ฆ๋์ค ๊ท์น์ ์ถ๊ฐํ๊ณ , validations๋ฅผ ์กฐ์ ํ๊ณ , use case๊ฐ ๋ชจ๋๊ณผ ์๋น์ค ๊ฒฝ๊ณ๋ฅผ ์กด์คํ๋์ง ํ์ธํด์ผ ํฉ๋๋ค.
์ค์: Lino ํ๋ก์ ํธ๋ CQRS ๋ฐ mediator ์ง์๊ณผ ํจ๊ป ์์ฑ๋ ์ ์์ต๋๋ค. ์์ฑ๋ Commands์ Queries๋ ์์ฒญ ๋ฐ ์์
๊ฒฐ๊ณผ ์ฒ๋ฆฌ๋ฅผ ํ์คํํ๊ธฐ ์ํด ICommand, IQuery, ICommandHandler, IQueryHandler, Tolitech.Results ๊ฐ์ ์ ํ๋ฆฌ์ผ์ด์
์ถ์ํ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
Use Cases ๊ฐ์
Use Case๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์์ ํ ์์ ์ ๋ํ๋ ๋๋ค. ์ ๋ ฅ ๋ชจ๋ธ์ ๋ฐ๊ณ , ๋ฐ์ดํฐ๋ฅผ ๊ฒ์ฆํ๊ณ , ์์กด์ฑ์ ์กฐ์จํ๊ณ , ํ์ํ ๋ ๋๋ฉ์ธ ๋์์ ํธ์ถํ๊ณ , ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๊ฑฐ๋ ์กฐํํ ๋ค ํ์คํ๋ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค. ์ด๋ ๋๋ฉ์ธ ๋ชจ๋ธ ๋ฐ์ผ๋ก ๋ถ๋ณ์์ ์ฎ๊ธฐ์ง ์์ผ๋ฉด์ ์ ํ๋ฆฌ์ผ์ด์ ์ด ๋น์ฆ๋์ค ํ๋ฆ์ ์ค์ผ์คํธ๋ ์ด์ ํ๋ ์์น์ ๋๋ค.
Lino๊ฐ ์์ฑํ ์๋ฃจ์ ์์ use cases๋ ์์ธก ๊ฐ๋ฅํ ๊ตฌ์กฐ๋ก ์ ํ๋ฆฌ์ผ์ด์ ํ๋ก์ ํธ์ ๊ทธ๋ฃนํ๋ฉ๋๋ค:
src/Services/<ServiceName>/<ModuleName>/Application/UseCases/<EntityName>/
โโโ Commands/
โ โโโ <CommandName>/
โโโ Queries/
โโโ <QueryName>/
์ด ๊ตฌ์ฑ์ ๊ฐ feature๊ฐ ์ด๋ค ์๋น์ค, ๋ชจ๋, ์ํฐํฐ์ ์ํ๋์ง ๋ช ํํ๊ฒ ๋ณด์ฌ ์ค๋๋ค. ๋ํ ํ๋ฉด, API, ํตํฉ ๋๋ background process๊ฐ ๋์์ ํ์ชฝ ๋ฉด๋ง ํ์๋ก ํ ๋ ์ ์ฉํ๋๋ก ์ฐ๊ธฐ ๋ชจ๋ธ๊ณผ ์ฝ๊ธฐ ๋ชจ๋ธ์ ๋ ๋ฆฝ์ ์ผ๋ก ์ ์งํฉ๋๋ค.
Command ๋๋ Query?
| ํ์ | ์๋ | ์์ | ์ผ๋ฐ์ ์ธ ๊ฒฐ๊ณผ |
|---|---|---|---|
| Command | ์์คํ ์ํ๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค. | CreateOrder, UpdateVehicle, DeleteMaintenance, SavePermissionsByRoleId. |
์ฑ๊ณต ์ Result, Result<CommandResult> ๋๋ no-content. |
| Query | ์ํ๋ฅผ ๋ณ๊ฒฝํ์ง ์๊ณ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ต๋๋ค. | GetOrderById, ListCustomers, GetVehicleAvailability. |
Result<QueryResult>, list, page ๋๋ consumer์ฉ ํน์ DTO. |
์ ํ๋ฆฌ์ผ์ด์ use case์ ์ํ๋ ๊ฒ
- ์ ๋ ฅ contract: ์์ ์ ํ์ํ ๋ฐ์ดํฐ๋ง ๊ฐ์ง command ๋๋ query record.
- Validation: handler๊ฐ ํ๋ฆ์ ์คํํ๊ธฐ ์ ์ ์์ฒญ ํ์, ํ์ ํ๋, ๋ฒ์, ์๋ณ์, filters ๋ฐ ๊ธฐํ ์ ๋ ฅ ์ ์ฝ์ ํ์ธํ๋ ๊ท์น.
- Handler ์ค์ผ์คํธ๋ ์ด์ : ์์กด์ฑ ํธ์ถ, repository ์ ๊ทผ, context ์กฐํ, Unit of Work ์ฌ์ฉ, ๊ฒฐ๊ณผ ๊ตฌ์ฑ, logging, tracing.
- ๊ฒฐ๊ณผ contract: caller๊ฐ ๊ณ์ ์งํํ๋ ๋ฐ ์ ํํ ํ์ํ ๊ฒ์ ์ ๋ฌํ๋ ์์ ์๋ต ๊ฐ์ฒด ๋๋ content ์๋ ๊ฒฐ๊ณผ.
use case ๋ฐ์ ์์ด์ผ ํ๋ ๊ฒ
- ๋๋ฉ์ธ ๋ถ๋ณ์์ ์ํฐํฐ, Value Objects, domain services, ๋๋ฉ์ธ ๋ฉ์๋์ ๋จ์ ์์ด์ผ ํฉ๋๋ค.
- Infrastructure ์ธ๋ถ ์ฌํญ์ abstractions, repositories, database contexts, file services, messaging integrations, external clients ๋ค์ ์์ด์ผ ํฉ๋๋ค.
- Presentation ๊ด์ฌ์ฌ, ์๋ฅผ ๋ค์ด UI ์ํ, labels, layouts, component ๋์์ web app ๊ณ์ธต์ ๋จ์ ์์ด์ผ ํฉ๋๋ค.
์ข์ use case๋ ๋ช ์์ ์ด๊ณ , ์ดํดํ ์ ์์ ๋งํผ ์์ผ๋ฉฐ, ๊ฒฝ๊ณ์ ์๊ฒฉํฉ๋๋ค. ์์ ์ ์กฐ์จํ์ง๋ง ์์คํ ์ ๋ชจ๋ ๊ท์น์ด ๋ค์์ด๋ ์ฅ์๊ฐ ๋์ง๋ ์์ต๋๋ค.
Commands
Command๋ ์์คํ
์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ๋์์ ์คํํ๋ ๋ฐ ํ์ํ ๋ฐ์ดํฐ๋ง ๋ด๋ ๋ถ๋ณ ๋ฉ์์ง์
๋๋ค. ์ผ๋ฐ์ ์ธ ์๋ก๋ CreateCustomer, UpdateVehicle, DeleteMaintenance, ConfirmOrder, SavePermissionsByRoleId๊ฐ ์์ต๋๋ค. Commands๋ ์ ํ๋ฆฌ์ผ์ด์
์ ๋ฌด์ธ๊ฐ๋ฅผ ์ํํ๋ผ๊ณ ์ง์ํ๋ฏ๋ก ๋์ ์ด๋ฆ์ผ๋ก ๋ช
๋ช
ํด์ผ ํฉ๋๋ค.
Lino์์ ์์ฑ๋ Commands๋ command ์ถ์ํ๋ฅผ ๊ตฌํํ๊ณ ํ์คํ๋ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ records์ ๋๋ค. ์์ฑ Commands๋ ๋ณดํต caller๊ฐ ์๊ตฌํ๋ ์๋ณ์๋ ์ต์ ์ ๋ณด๋ฅผ ๋ด์ ๊ฒฐ๊ณผ ๊ฐ์ฒด๋ฅผ ๋ฐํํ๊ณ , ์ ๋ฐ์ดํธ์ ์ญ์ commands๋ ์์ ์ด ์ฑ๊ณต์ ์ผ๋ก ์๋ฃ๋๋ฉด ์ผ๋ฐ์ ์ผ๋ก no-content๋ฅผ ๋ฐํํฉ๋๋ค.
Command์ ํน์ง
- ๋ถ๋ณ์ฑ:
record๋๋get๋ง ์๋ ํด๋์ค์ฒ๋ผ ๊ณต๊ฐ mutable setters ์์ด ๊ตฌํ๋ฉ๋๋ค. - ๋ช
๋ นํ ์ด๋ฆ:
CreateOrder,UpdateCustomerAddress,ChangeProductPrice์ฒ๋ผ ๋น์ฆ๋์ค ๋์์ ๋ฐ์ํฉ๋๋ค. - ์ต์ ๋ฐ์ดํฐ: ์ ์ฒด ์ํฐํฐ๋ ๋๋ ๋ฐ์ดํฐ๋ฅผ ์ด๋ฐํ์ง ์๊ณ ์์ ์คํ์ ํ์ํ ํ๋๋ง ํฌํจํฉ๋๋ค.
- ๋ถ๋ฆฌ๋ ๊ฒ์ฆ: ๊ฐ Command๋ ์์ฒญ์ด handler์ ๋๋ฌํ๊ธฐ ์ ์ ์ผ๊ด์ฑ์ ๋ณด์ฅํ๋ ์์ฒด ๊ท์น์ ๊ฐ์ง๋๋ค.
- UI ๋ ๋ฆฝ์ฑ: Command๋ ์์ ์ ์์ํ ๋ฒํผ, ํผ ๋๋ ์ปดํฌ๋ํธ๊ฐ ์๋๋ผ ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋๋ฅผ ๋ํ๋ ๋๋ค.
Command๋ฅผ ๋ง๋ค์ด์ผ ํ๋ ๊ฒฝ์ฐ
- ๋ฐ์ดํฐ๊ฐ ์์ฑ, ๋ณ๊ฒฝ, ์ ๊ฑฐ, ์ฐ๊ฒฐ, ๊ฐ์ ธ์ค๊ธฐ, ์น์ธ, ์ทจ์๋๊ฑฐ๋ ์ด๋ค ๋ฐฉ์์ผ๋ก๋ ๋ณ๊ฒฝ๋ ๋ Command๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- payload๋ ์์ ์ ์ง์ค๋๊ฒ ์ ์งํฉ๋๋ค. ๋ช ๊ฐ์ ํ๋๋ง ์ถฉ๋ถํ๋ค๋ฉด ์ ์ฒด ์ํฐํฐ๋ฅผ ์ ๋ฌํ์ง ์์ต๋๋ค.
- ์์ํ ์๊ฐ์ ์ด๋ฒคํธ๊ฐ ์๋๋ผ ๋น์ฆ๋์ค ๋์์ ์ค๋ช ํ๋ ์ด๋ฆ์ ์ ํธํฉ๋๋ค.
- ๋์์ด ํ์ฌ ๋ชจ๋์ ์ํ๋์ง, ์๋๋ฉด ๋ค๋ฅธ ๋ชจ๋์ ํตํฉ, ์ด๋ฒคํธ ๋๋ shadow entity๋ก ํํ๋์ด์ผ ํ๋์ง ๊ฒํ ํฉ๋๋ค.
Command Validators
Command Validators๋ Command๊ฐ handler๋ก ์ ์ก๋๊ธฐ ์ ์ ์ ๊ตฌ์ฑ๋์ด ์๊ณ ์ ๋ ฅ ์๊ตฌ ์ฌํญ์ ์ถฉ์กฑํ๋์ง ๋ณด์ฅํฉ๋๋ค. Lino์์ ์ด๋ฌํ ๊ฒ์ฆ์ ๊ท์น์ ๋ง๋ค๊ธฐ ์ํ ์ ์ฐฝํ๊ณ ์ฝ๊ธฐ ์ฌ์ด API๋ฅผ ์ ๊ณตํด .NET ํ๋ก์ ํธ์์ ํํ ์ฐ์ด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ธ FluentValidation์ผ๋ก ๊ตฌํ๋ฉ๋๋ค.
์ผ๋ฐ์ ์ธ ๊ฒ์ฆ ๊ท์น
- ํ์ ํ๋์๋
NotEmpty๋ฐNotNull. - ์ซ์ ๋ฒ์, ๊ธ์ก, ๋ฐฑ๋ถ์จ, ์ต์ ๋ฐ ์ต๋ ์๋์๋
InclusiveBetween. - ๋ฌธ์์ด ๊ธธ์ด์๋
MaximumLength,MinimumLength,Length. List<T>์ ๊ฐ์ ์ปฌ๋ ์ ํญ๋ชฉ ๊ฒ์ฆ์๋RuleForEach.- ๋ฌธ์ ํ์, ๋ ์ง ์ผ๊ด์ฑ, ์๋ชป๋ ํ๋ ์กฐํฉ ๊ฐ์ ์ฌ์ฉ์ ์ง์ ๊ท์น์๋
Must.
validator๋ ์ ๋ ฅ ๊ฒฝ๊ณ๋ฅผ ๋ณดํธํฉ๋๋ค. ์ํ ์ ํ, ํ์ฉ๋ ์ ์ด, caller์ ๋ฌด๊ดํ๊ฒ ํญ์ ์ฑ๋ฆฝํด์ผ ํ๋ ๊ท์น ๊ฐ์ ์ค์ ๋๋ฉ์ธ ๋ถ๋ณ์์ ๊ณ์ aggregate, ์ํฐํฐ, Value Object ๋๋ domain service์ ์ํฉ๋๋ค.
Command Handlers
Command Handler๋ Command์ ์ฐ๊ฒฐ๋ ์ ํ๋ฆฌ์ผ์ด์
๋ก์ง์ ์คํํฉ๋๋ค. ํ์ํ ๋ repository, context, IUnitOfWork, ๋ณด์กฐ ์๋น์ค, logging, tracing, ํตํฉ ํธ์ถ, ๋๋ฉ์ธ ์ด๋ฒคํธ๋ฅผ ์ค์ผ์คํธ๋ ์ด์
ํฉ๋๋ค.
handler ๊ตฌํ ํจํด
- repository, ์ธ๋ถ ์๋น์ค, context, Unit of Work ๊ฐ์ ์์กด์ฑ์ dependency injection์ผ๋ก ๋ฐ์ต๋๋ค.
- ์์ ์ ํ์ํ ๋ฐ์ดํฐ์ ์กด์ฌ ์ฌ๋ถ์ ์ฌ์ฉ ๊ฐ๋ฅ์ฑ์ ๊ฒ์ฆํฉ๋๋ค.
- ์์ ์ด ๊ธฐ์กด ์ํ์ ์์กดํ ๋ ์ฌ๋ฐ๋ฅธ aggregate ๋๋ ์ํฐํฐ๋ฅผ ๋ก๋ํฉ๋๋ค.
- handler์์ ๋ถ๋ณ์์ ์ค๋ณตํ์ง ์๊ณ ๋๋ฉ์ธ ๋ฉ์๋๋ฅผ ํธ์ถํฉ๋๋ค.
IUnitOfWork๋๋ ํ๋ก์ ํธ์ persistence ์ถ์ํ๋ฅผ ํตํด ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฅํฉ๋๋ค.- ์์ ์ด ์์คํ ์ ๋ค๋ฅธ ๋ถ๋ถ๊ณผ ํต์ ํด์ผ ํ ๋ ๋๋ฉ์ธ ์ด๋ฒคํธ, Outbox ๋๋ ํตํฉ์ ๋ฑ๋กํฉ๋๋ค.
- ์ฑ๊ณต, ์๋ ค์ง ์คํจ ๋๋ ์ต์ ์๋ต ๋ฐ์ดํฐ๋ฅผ ๋ด์
Result๋๋Result<T>๋ฅผ ๋ฐํํฉ๋๋ค.
Command Results ๋ฐ Result Pattern
Command Result๋ caller๊ฐ ๊ณ์ ์งํํ๋ ๋ฐ ํ์ํ ๋ฐ์ดํฐ๋ง ๊ฐ์ง ๋จ์ DTO์ฌ์ผ ํฉ๋๋ค. ์์ฑ์์๋ ๋ณดํต ์์ฑ๋ Id๋ฅผ ํฌํจํฉ๋๋ค. ์
๋ฐ์ดํธ๋ ์ญ์ ์์๋ payload๊ฐ ์์ ์ ์์ต๋๋ค. ์์
์ด ์์๋ ์กฐ๊ฑด์ผ๋ก ์คํจํ๋ฉด ๋ฐํ๊ฐ์ ํ์คํ๋ ์ค๋ฅ ์ ๋ณด๋ฅผ ๋ด์์ผ ํฉ๋๋ค.
Result Pattern์ ์์
๊ฒฐ๊ณผ๋ฅผ ์ฑ๊ณต ๋๋ ์คํจ๋ก ์บก์ํํฉ๋๋ค. ์ํฐํฐ๋ฅผ ์ฐพ์ ์ ์์, ์๋ชป๋ ์ํ, ๋น์ฆ๋์ค ๊ฒ์ฆ ๊ฐ์ ์์ธก ๊ฐ๋ฅํ ์๋๋ฆฌ์ค์ ์์ธ๋ฅผ ๋์ง๋ ๋์ , handler๋ ํ์ํ ๋ ๊ฐ, ์ค๋ฅ, ๋ฉํ๋ฐ์ดํฐ๋ฅผ ํฌํจํ Result<T> ๊ฐ์ ํ์
์ ๋ฐํํฉ๋๋ค.
- ์ฑ๊ณต ์ ๊ฒฐ๊ณผ๋ ์์ DTO ๋๋ ์์ฑ๋ ์๋ณ์ ๊ฐ์
Value๋ฅผ ๋ ธ์ถํ ์ ์์ต๋๋ค. - ์คํจ ์ ๊ฒฐ๊ณผ๋ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ error definitions์ ์์ฃผ ์ ์๋๋ ํ์คํ๋ ์ฝ๋๋ ๋ฉ์์ง๋ฅผ ์ ์ฅํฉ๋๋ค.
- ์ค๋ฅ ์ฒ๋ฆฌ ํ๋ฆ์ Application, API, typed clients, UI ์ ๋ฐ์์ ์ผ๊ด๋๊ฒ ์ ์ง๋ฉ๋๋ค.
CLI๋ก Command ๋ง๋ค๊ธฐ
Lino๋ ๋ค์ command๋ฅผ ํตํด ์ Command์ ํ์ํ artifacts ์์ฑ์ ๋จ์ํํฉ๋๋ค:
lino command new
CLI๋ ๋ง๋ฒ์ฌ์ ์ง๋ฌธ์ ์ค์ด๊ธฐ ์ํ ์ต์ ๋ ํ์ฉํฉ๋๋ค:
lino command new --service <ServiceName> --module <ModuleName> --entity <EntityName> --name <CommandName> lino command new --name <CommandName> --service <ServiceName> --module <ModuleName> --entity <EntityName> lino command list --service <ServiceName> --module <ModuleName> --entity <EntityName>
-s๋๋--service: ๋์ ์๋น์ค.-m๋๋--module: ๋ชจ๋ํ๋ ์๋น์ค์ ๋์ ๋ชจ๋.-e๋๋--entity: Command์ ์ฐ๊ฒฐ๋ ์ํฐํฐ.-n,--name,-c๋๋--command: Command ์ด๋ฆ.
๋ํํ ํ๋ฆ ์ค Lino๋ ์๋น์ค, ๋ชจ๋, ์ํฐํฐ, Command ์ด๋ฆ, Command ํ์ , ๊ทธ๋ฆฌ๊ณ ์์ฑ ๋๋ ์ ๋ฐ์ดํธ ์์ ์ ๊ฒฝ์ฐ ์์ฒญ์ ํฌํจ๋ ์์ฑ์ ํ์ธํฉ๋๋ค. CLI๊ฐ ๋ ธ์ถํ๋ ํ์ ์ Create, Update, Delete์ ๋๋ค.
ํ์ธ ํ Lino๋ ๋ค์๊ณผ ๊ฐ์ ํ์ผ์ ์์ฑํฉ๋๋ค:
CreateOrderCommand.csCreateOrderCommandValidator.csCreateOrderCommandHandler.csCreateOrderCommandResult.cs
์์ฑ๋ ๊ตฌ์กฐ ์์
CreatePerson Command๋ฅผ ๊ณ ๋ คํด ๋ณด์ธ์. ์์ฑ๋ ๊ตฌ์กฐ๋ ๋ค์๊ณผ ๋น์ทํฉ๋๋ค:
<ProjectName>/
โโโ src/
โโโ Services/
โโโ <ServiceName>/
โโโ Application/
โโโ <ProjectName>.<ServiceName>.Application.csproj
โโโ UseCases/
โโโ People/
โโโ Commands/
โ โโโ CreatePerson/
โ โโโ CreatePersonCommand.cs
โ โโโ CreatePersonCommandValidator.cs
โ โโโ CreatePersonCommandHandler.cs
โ โโโ CreatePersonCommandResult.cs
โโโ Queries/
โโโ ...
Fleet์ ์ฌ์ฉ์ ์ง์ Command๋ ๊ฐ์ ํจํด์ ๋ฐ๋ฆ ๋๋ค:
Application/UseCases/Vehicles/Commands/UpdateVehicle/ โโโ UpdateVehicleCommand.cs โโโ UpdateVehicleCommandValidator.cs โโโ UpdateVehicleCommandHandler.cs โโโ UpdateVehicleCommandResult.cs
Command ํ์ผ์ ์ฑ ์
- Command: ์์ ์ ๋ ฅ์ ๋ด๋ ๋ถ๋ณ ์์ฒญ contract.
- Validator: ์ผ๋ฐ์ ์ผ๋ก ํ์ ์ฌ๋ถ, ๊ธธ์ด, ๋ฒ์, ์๋ณ์, ์ปฌ๋ ์ ๊ท์น์ ํฌํจํ๋ ์ ๋ ฅ ๊ฒ์ฆ.
- Handler: repository, Unit of Work, context, ๋๋ฉ์ธ ๋ฉ์๋, logging, tracing, ๊ฒฐ๊ณผ ์์ฑ์ ์ค์ผ์คํธ๋ ์ด์ ํฉ๋๋ค.
- Result: ๋ฐ์ดํฐ๋ฅผ ๋ฐํํด์ผ ํ๋ ์ฑ๊ณต ์์ ์ ์ํ ์ต์ ์๋ต contract.
๊ตฌํ ์ฒดํฌ๋ฆฌ์คํธ
lino command new๋ฅผ ์คํํ๊ณ ์ฌ๋ฐ๋ฅธ ์๋น์ค, ๋ชจ๋, ์ํฐํฐ, ํ์ , ์์ฑ์ ์ ํํฉ๋๋ค.- ์์ฑ๋ Command๋ฅผ ์ด๊ณ ์์ contract์ ์ํ์ง ์๋ ํ๋๋ฅผ ์ ๊ฑฐํฉ๋๋ค.
- ์๋์ผ๋ก ์ถ๋ก ํ ์ ์๋ ๋น์ฆ๋์ค ์ ๋ ฅ ๊ท์น์ผ๋ก validator๋ฅผ ๊ฐํํฉ๋๋ค.
- handler๋ฅผ ๊ฒํ ํ๊ณ ์ ํ๋ฆฌ์ผ์ด์ ๊ณ์ธต์์ ๋ถ๋ณ์์ ์ค๋ณตํ์ง ์๊ณ ๋๋ฉ์ธ ๋์์ ํธ์ถํ๋์ง ๋ณด์ฅํฉ๋๋ค.
- persistence์๋
IUnitOfWork๋ฅผ ์ฌ์ฉํ๊ณ , ์์ ์ด ์ ๋ขฐํ ์ ์๋ ์ด๋ฒคํธ ๋๋ Outbox๋ ์๊ตฌํ ๋๋ transactional save๋ฅผ ์ ํธํฉ๋๋ค. - ์์๋ ๋น์ฆ๋์ค ๊ฒฐ๊ณผ์๋ ์์ธ๊ฐ ์๋๋ผ
Result์ค๋ฅ๋ก ์คํจ๋ฅผ ๋ฐํํฉ๋๋ค. - Command๋ฅผ ํธ์ถํ endpoint, page ๋๋ integration์ ์ปดํ์ผํ๊ณ ํ ์คํธํฉ๋๋ค.
์ค๋ฌด ๊ท์น: generator๋ architectural skeleton์ ์ ๊ณตํฉ๋๋ค. ์ต์ข ์ ํ์ฑ์ ๋๋ฉ์ธ ์ธ์ด, ๋ถ๋ณ์, persistence ์๊ตฌ ์ฌํญ, ๋ชจ๋ ๊ฒฝ๊ณ์ ๋น์ถ์ด use case๋ฅผ ๊ฒํ ํ๋ ๋ฐ์ ๋์ต๋๋ค.
Queries
Query๋ ๋๋ฉ์ธ ์ํ๋ฅผ ๋ณ๊ฒฝํ์ง ์๊ณ ๋ฐ์ดํฐ๋ฅผ ์ป์ผ๋ ค๋ ์๋๋ฅผ ๋ํ๋ ๋๋ค. Queries๋ ํจ์จ์ ์ธ ์ฝ๊ธฐ๋ฅผ ์ํด ์ค๊ณ๋๋ฉฐ, ํ์ํ์ง ์์ ๋ ์ ์ฒด ์ํฐํฐ๋ฅผ ๋ก๋ํ์ง ์๊ณ caller์๊ฒ ํ์ํ ํ๋๋ง ์ ํํ ๋ฐํํฉ๋๋ค.
์ผ๋ฐ์ ์ธ ์๋ก๋ GetCustomerById, ListCustomers, ListPhoneTypes, ListOrdersByDateRange, ๊ทธ๋ฆฌ๊ณ GetVehicleAvailability ๊ฐ์ ์ฌ์ฉ์ ์ง์ query๊ฐ ์์ต๋๋ค. Query๋ ์ ํ๋ฆฌ์ผ์ด์
์ ํน์ ์ง๋ฌธ์ ๋ตํด์ผ ํฉ๋๋ค.
Query์ ํน์ง
- ๋ถ๋ณ: Commands์ ๋ง์ฐฌ๊ฐ์ง๋ก Query๋ ์์ฑ๋ ํ ๋ณ๊ฒฝ์ ํ์ฉํ์ง ์์์ผ ํฉ๋๋ค.
- ์ค๋ช
์ ์ธ ์ด๋ฆ:
GetCustomerById๋๋ListOrdersByDateRange์ฒ๋ผ ์ฐพ๋ ์ ๋ณด๋ฅผ ๋ฐ์ํฉ๋๋ค. - Filters ๋ฐ pagination: dates, status, page, page size, search text, ordering ๋ฐ ๊ธฐํ ์ฝ๊ธฐ parameters๋ฅผ ๋ด์ ์ ์์ต๋๋ค.
- Projection: ๋๋ฉ์ธ ์ํฐํฐ๋ฅผ ์ง์ ๋ ธ์ถํ์ง ์๊ณ ํ์ํ ํ๋๋ง ๊ฐ์ง DTO ๋๋ view model์ ๋ฐํํด์ผ ํฉ๋๋ค.
- ๋ถ์์ฉ ์์: ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ฑฐ๋ database์ ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฅํด์๋ ์ ๋ฉ๋๋ค.
Query๋ฅผ ๋ง๋ค์ด์ผ ํ๋ ๊ฒฝ์ฐ
- ์์ ์ด ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ ์ํ๋ฅผ ๋ณ๊ฒฝํด์๋ ์ ๋ ๋ Query๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- ์์ธ ํ๋ฉด, ์๋ณ์ ๊ฒ์, availability checks ๋๋ ๋จ์ผ ๊ฐ์ฒด ์๋ต์๋ ๋จ์ผ ๊ฒฐ๊ณผ Query๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- grids, option lists, child collections, selection controls์๋ list Query๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- grids ๋ฐ ์ ์ฌ์ ์ผ๋ก ํฐ ๋ฐ์ดํฐ ์ธํธ์๋ pagination์ ์ฌ์ฉํฉ๋๋ค.
- ์์ reference data, enumerations, options endpoints์๋ ๋จ์ lists๋ฅผ ์ฌ์ฉํฉ๋๋ค.
Query Validators
Query Validators๋ filters, pagination values, date ranges, identifiers, visibility rules ๊ฐ์ ์ ๋ ฅ parameters๋ฅผ ๊ฒ์ฆํฉ๋๋ค. ์ด๋ค๋ FluentValidation์ผ๋ก ๊ตฌํ๋ฉ๋๋ค.
Queries์ ์ผ๋ฐ์ ์ธ ๊ฒ์ฆ ๊ท์น
- ์์์ผ๊ณผ ์ข
๋ฃ์ผ ๊ฐ์ range filters์๋
GreaterThanOrEqualTo๋ฐLessThanOrEqualTo. - ์ด๋ฆ, email, search term ๊ฐ์ text filters์๋
Length,MaximumLength,MinimumLength. page๋ฐpageSize๋ฅผ ์ ํํ๋ pagination์๋InclusiveBetween.- detail queries์ ํ์ identifiers์๋
NotEmpty. - ์ข
๋ฃ์ผ์ด ์์์ผ๋ณด๋ค ๋น ๋ฅธ ๊ฒฝ์ฐ์ฒ๋ผ ์๋ชป๋ filter ์กฐํฉ์๋
Must.
Query Handlers
Query Handler๋ repositories ๋๋ database context๋ฅผ ์กฐํํ๊ณ ์ต์ ํ๋ projections๋ฅผ ๋ฐํํฉ๋๋ค. Lino์์๋ ์ ์ ํ ๋ Select๋ฅผ ์ฌ์ฉํ projections, ๋ช
์์ filters, ์์ธก ๊ฐ๋ฅํ ordering, no-tracking reads๋ฅผ ๊ถ์ฅํฉ๋๋ค.
Query handler๋ read-only์ฌ์ผ ํฉ๋๋ค. ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ๋๋ฉ์ธ ๋ฉ์๋๋ฅผ ํธ์ถํ์ง ์๊ณ , ์์ ๋ณ๊ฒฝ์ ๋ฐ์์ํค์ง ์์ผ๋ฉฐ, SaveChanges๋ฅผ ์คํํ์ง ์์ต๋๋ค. ์ฝ๊ธฐ ์์
์ด audit์ ๊ธฐ๋กํ๊ฑฐ๋ integration์ ์์ํ๊ฑฐ๋ ์ํ๋ฅผ ์ฌ๊ณ์ฐํด์ผ ํ๋ค๋ฉด, ์ด๋ ๋ณดํต ๋ค๋ฅธ use case ๋๋ ๋ณ๋ process๊ฐ ํ์ํ๋ค๋ ์ ํธ์
๋๋ค.
Query Results
Lino์์ Queries์ ๊ฒฐ๊ณผ๋ QueryResult suffix๊ฐ ๋ถ์ records๋ก ํํ๋ฉ๋๋ค. ์ด convention์ ๋จ์ผ ์๋ต, ๋จ์ list, paginated list, ๋๋ ํ๋ฉด, API, integration, background process์ฉ ํน์ DTO ๋ชจ๋์ ์ ์ฉ๋ฉ๋๋ค.
query results๋ ์์ ์ ์ธ read contracts์ฌ์ผ ํฉ๋๋ค. ๋๋ฉ์ธ ์ํฐํฐ๋ฅผ ์ง์ ๋ ธ์ถํ๊ธฐ ์ํ shortcut์ด ์๋๋ผ consumer๋ฅผ ์ํด ์ค๊ณ๋ DTOs๋ก ๋ค๋ฃจ์ธ์.
CLI๋ก Query ๋ง๋ค๊ธฐ
Commands์ ๋น์ทํ๊ฒ Lino๋ ๋ค์ command๋ฅผ ์ ๊ณตํฉ๋๋ค:
lino query new
CLI๋ ๋ค์๊ณผ ๊ฐ์ ์ต์ ๋ ํ์ฉํฉ๋๋ค:
lino query new --service <ServiceName> --module <ModuleName> --entity <EntityName> --name <QueryName> lino query new --name <QueryName> --service <ServiceName> --module <ModuleName> --entity <EntityName> lino query list --service <ServiceName> --module <ModuleName> --entity <EntityName>
-s๋๋--service: ๋์ ์๋น์ค.-m๋๋--module: ๋์ ๋ชจ๋.-e๋๋--entity: Query์ ์ฐ๊ฒฐ๋ ์ํฐํฐ.-n,--name,-q๋๋--query: Query ์ด๋ฆ.
๋ํํ ํ๋ฆ ์ค Lino๋ Query๊ฐ ๋จ์ผ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋์ง list๋ฅผ ๋ฐํํ๋์ง ๋ฌป์ต๋๋ค. ์๋ต์ด list์ด๋ฉด pagination์ด ํ์ํ์ง๋ ๋ฌป์ต๋๋ค. ๋ง์ง๋ง์ผ๋ก ๋ฐํ๋๊ฑฐ๋ ์์ฑ๋ projection์์ ์ฌ์ฉ๋ ์์ฑ์ ์ ํํ ์ ์๊ฒ ํฉ๋๋ค.
Lino๋ ์๋์ผ๋ก ๋ค์์ ์์ฑํฉ๋๋ค:
GetOrderByIdQuery.csGetOrderByIdQueryValidator.csGetOrderByIdQueryHandler.csGetOrderByIdQueryResult.cs
Queries์ฉ ์์ฑ ๊ตฌ์กฐ ์์
<ProjectName>/
โโโ src/
โโโ Services/
โโโ <ServiceName>/
โโโ Application/
โโโ <ProjectName>.<ServiceName>.Application.csproj
โโโ UseCases/
โโโ Orders/
โโโ Commands/
| โโโ ...
โโโ Queries/
โโโ GetOrderById/
โโโ GetOrderByIdQuery.cs
โโโ GetOrderByIdQueryValidator.cs
โโโ GetOrderByIdQueryHandler.cs
โโโ GetOrderByIdQueryResult.cs
Vehicle availability์ฉ ์ฌ์ฉ์ ์ง์ Query๋ ๊ฐ์ ํจํด์ ๋ฐ๋ฆ ๋๋ค:
Application/UseCases/Vehicles/Queries/GetVehicleAvailability/ โโโ GetVehicleAvailabilityQuery.cs โโโ GetVehicleAvailabilityQueryValidator.cs โโโ GetVehicleAvailabilityQueryHandler.cs โโโ GetVehicleAvailabilityQueryResult.cs
Query ํ์ผ์ ์ฑ ์
- Query: identifiers, filters, ordering, pagination ๋๋ date ranges๋ฅผ ๋ด๋ ๋ถ๋ณ ์์ฒญ contract.
- Validator: identifiers, pagination, required filters, date ranges, search criteria ๊ฒ์ฆ.
- Handler: application context, projections, filters, ordering, pagination, logging, tracing, ๊ฒฐ๊ณผ ์์ฑ์ ์ฌ์ฉํ read orchestration.
- Result: caller๋ฅผ ์ํด ๋ชจ๋ธ๋ง๋ response DTO์ด๋ฉฐ, list items๋ฅผ ์ํ ๋ด๋ถ records๋ฅผ ์์ฃผ ํฌํจํฉ๋๋ค.
๊ตฌํ ์ฒดํฌ๋ฆฌ์คํธ
lino query new๋ฅผ ์คํํ๊ณ ์๋น์ค, ๋ชจ๋, ์ํฐํฐ, Query ์ด๋ฆ, ๋ฐํ ํ์ , pagination mode, ์์ฑ์ ์ ํํฉ๋๋ค.- ์์ฒญ contract๋ฅผ ๊ฒํ ํ๊ณ caller์๊ฒ ์ค์ ๋ก ํ์ํ filters๋ง ์ ์งํฉ๋๋ค.
- ํนํ ํ์ identifiers, date ranges, page size limits, ์๋ชป๋ filter ์กฐํฉ์ ๋ํด validator๋ฅผ ๊ฐํํฉ๋๋ค.
- handler projection์ ์กฐ์ ํด UI, API, integration ๋๋ background process๊ฐ ์๊ตฌํ๋ ํ๋๋ง ๋ฐํํ๊ฒ ํฉ๋๋ค.
- Query๋ฅผ read-only๋ก ์ ์งํฉ๋๋ค. ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ๋๋ฉ์ธ ๋ฉ์๋๋ฅผ ํธ์ถํ์ง ์๊ณ handler์์ ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฅํ์ง ์์ต๋๋ค.
- ์ ์ ํ ๋ ๊ธฐ์กด ํ์ค ์ค๋ฅ๋ฅผ ์ฌ์ฉํด ์์๋ ์คํจ๋ฅผ
Result๋ก ์ ํํฉ๋๋ค. - API endpoint, Blazor page, in-process integration ๋๋ typed client์ฒ๋ผ Query๋ฅผ ํธ์ถํ๋ consumer๋ฅผ ์ปดํ์ผํ๊ณ ํ ์คํธํฉ๋๋ค.
์ฌ์ฉ์ ์ง์ Query ์์
SaaS์ ๋ชจ๋ ๊ฐ integration ํ๋ฆ์์๋ lino query new๋ก vehicle availability์ ๋ํ ์ฌ์ฉ์ ์ง์ Query๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. ์์ฑ๋ ๊ตฌ์กฐ๋ Query, Handler, Result, Validator๋ฅผ ์ ๊ณตํฉ๋๋ค. ๊ทธ ๋ค์ ๊ฐ๋ฐ์๋ vehicle identifier, start date, end date ๊ฐ์ ํ์ํ ์
๋ ฅ์ ์ถ๊ฐํ๊ณ , range๊ฐ ์ฌ๋ฐ๋ฅธ์ง ๊ฒ์ฆํ๊ณ , handler logic์ ๊ตฌํํฉ๋๋ค. ์ด๊ฒ์ด ๊ธฐ๋๋๋ ํ๋ฆ์
๋๋ค. ๋จผ์ ์ผ๊ด๋ ๊ตฌ์กฐ๋ฅผ ์์ฑํ ๋ค ๋ช
์์ ์ธ ์ฝ๋๋ก ๋๋ฉ์ธ๋ณ ๋์์ ์์ฑํฉ๋๋ค.
Read model ์ง์นจ: Query results๋ ์์ ์ ์ธ contracts์ฌ์ผ ํฉ๋๋ค. ๋๋ฉ์ธ ์ํฐํฐ๋ฅผ ์ง์ ๋ ธ์ถํ๊ธฐ ์ํ shortcut์ด ์๋๋ผ caller๋ฅผ ์ํด ์ค๊ณ๋ DTOs๋ก ๋ค๋ฃจ์ธ์.
๊ฒฐ๋ก
Lino์์ use cases๋ฅผ ์ ์ํ๋ค๋ ๊ฒ์ ๋๋ฉ์ธ ๋ชจ๋ธ์ ๋ช ํํ ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ผ๋ก ๋ฐ๊พธ๋ ๊ฒ์ ๋๋ค. Commands๋ ์ํ ๋ณ๊ฒฝ์ ์ฒ๋ฆฌํ๊ณ , Queries๋ ์ฝ๊ธฐ๋ฅผ ์ฒ๋ฆฌํ๋ฉฐ, validators๋ ์ ๋ ฅ ๊ฒฝ๊ณ๋ฅผ ๋ณดํธํ๊ณ , handlers๋ ํ๋ฆ์ ์ค์ผ์คํธ๋ ์ด์ ํ๋ฉฐ, ๊ฒฐ๊ณผ ๊ฐ์ฒด๋ ์ถ๋ ฅ์ ํ์คํํฉ๋๋ค.
๊ฐ์ฅ ๋น ๋ฅธ ํ๋ฆ์ ๋ณดํต ๋๋ฉ์ธ์ ๋ชจ๋ธ๋งํ๊ณ , ํ์ํ Commands์ Queries๋ฅผ ์์ฑํ๊ณ , ์์ฑ๋ ํ์ผ์ ๊ฒํ ํ๊ณ , ๋น์ฆ๋์ค ๋์์ ์์ฑํ๊ณ , ํ์ํ ๋ API ๋๋ page๋ก use case๋ฅผ ๋ ธ์ถํ ๋ค build์ tests๋ก ๋ชจ๋ ๊ฒ์ฆํ๋ ๊ฒ์ ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด architectural control์ ์์ง ์์ผ๋ฉด์ ๊ฐ๋ฐ ์๋๋ฅผ ์ ์งํ ์ ์์ต๋๋ค.
ํ๋ก์ ํธ๊ฐ ์ปค์ง์๋ก ๊ฐ use case๋ฅผ ํ๋์ ๋น์ฆ๋์ค ์๋์ ์ง์ค์ํค๊ณ , ์๋น์ค์ ๋ชจ๋ ๊ฒฝ๊ณ๋ฅผ ์กด์คํ๋ฉฐ, ๋ค๋ฅธ ๋ชจ๋์ด ํ๋ก์ธ์ค์ ์ฐธ์ฌํด์ผ ํ ๋๋ ์ด๋ฒคํธ, ํตํฉ ๋๋ shadow entities๋ฅผ ์ฌ์ฉํฉ๋๋ค.
