MediatR.Courier #1

MediatR.Courier ๋Š” CQRS ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ํ™•์žฅํŒ์œผ๋กœ
Event ๊ณต์œ ๋ฅผ ๋ชฉ์ ์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.
WPF Prism eventaggregator ๋น„์Šทํ•œ ๊ธฐ๋Šฅ์„ ํ•ฉ๋‹ˆ๋‹ค.
๋ณธ ์•„ํ‹ฐํด์—์„œ๋Š” Blazor๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

MediatR
MediatR.Courier

๋‘ Library ๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•˜๋ฉฐ blazor์— ์ ์šฉ์‹œ์—๋Š” Program.cs์—

var assemblies = AppDomain.CurrentDomain.GetAssemblies();
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(assemblies[0]))
            .AddCourier(assemblies);

์˜์กด์„ฑ์„ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.

Model ์„ ์–ธ

public class ExampleEvent : INotification
{
    public string message { get; set; }
}
INotification ์ƒ์† ๋ฐ›์Šต๋‹ˆ๋‹ค.

์ˆ˜์‹ ๋ถ€

//๊ตฌ๋… ์„ ์–ธ
Courier.Subscribe<ExampleEvent>(EventRecv); 
//์‹คํ–‰๋ถ€
public void EventRecv(ExampleEvent exam, CancellationToken tk)    
    {
        msg = exam.message;
        StateHasChanged();
    }
    

์ „ํŒŒ๋ถ€

 async Task PubMes()
    {
        ExampleEvent ev = new ExampleEvent() { message = inpumsg };
        await _mediator.Publish(ev); 
    }

image

BLAZOR PAGE์— ๋ชจ๋“ˆ์„ ๋ฐฐ์น˜ํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ

5 Likes

๋ธ”๋ ˆ์ด์ €๋กœ ํ•˜๋‹ˆ ์ž˜ ์™€๋‹ฟ์ง€ ์•Š์•„ ๋ทฐ๋ชจ๋ธ๊ฐ„ ์ฒ˜๋ฆฌ ํ•˜๋Š”๊ฑธ ์ฐพ์•„ ๋ดค์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์ด๊ฑด ์ฝ”๋“œํ”„๋กœ์ ํŠธ
https://www.codeproject.com/Tips/1074227/Mediator-a-communicator-between-ViewModels

๋•๋ถ„์— ํ™œ์šฉ ๋ฐฉ์•ˆ ๋ฐฐ์šฐ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค.
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

3 Likes

wpf์—์„œ๋Š” Mediator๋ณด๋‹ค prism event eventaggregator ๋”์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ^^
wpf์—์„œ๋Š” Mediator ์— publish ๋ณด๋‹ค Send๋กœ CQRS ํŒจํ„ด์œผ๋กœ ์ œ์ž‘ํ•œ ์•„ํ‹ฐํด๋„
์ž‘์„ฑํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ^^

3 Likes

Community Toolkit MVVM์˜ Messenger์™€ ์–ด๋–ค ์ฐจ์ด์ ์ด ์žˆ๋Š”์ง€ ์•Œ๋ ค์ฃผ์‹ค ์ˆ˜ ์žˆ์„๊นŒ์š”?

3 Likes

์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ^^ toolkit ์€ ํ•ด๋ณด์ง€ ์•Š์•„์„œ prism ๊นŒ์ง€ ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.
์•„๋ฌด๋ž˜๋„ web ์œ„์ฃผ๋กœ ํ•˜๋‹ค๋ณด๋‹ˆ

4 Likes