- [DEVEXPRESS] Hỗ trợ tìm kiếm highlight không dấu và không khoảng cách trên Gridview Filter
- [C#] Chia sẻ source code phần mềm Image Downloader tải hàng loạt hình ảnh từ danh sách link url
- [C#] Chụp hình và quay video từ camera trên winform
- [C#] Chia sẽ full source code tách file Pdf thành nhiều file với các tùy chọn
- Giới thiệu về Stock Tracker Widget - Công cụ theo dõi cổ phiếu và cảnh báo giá tăng giảm bằng C# và WPF
- [VB.NET] Chia sẻ công cụ nhập số tiền tự động định dạng tiền tệ Việt Nam
- [VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word
- [VB.NET] Hướng dẫn chọn nhiều dòng trên Datagridview
- Hướng Dẫn Đăng Nhập Nhiều Tài Khoản Zalo Trên Máy Tính Cực Kỳ Đơn Giản
- [C#] Chia sẻ source code phần mềm đếm số trang tập tin file PDF
- [C#] Cách Sử Dụng DeviceId trong C# Để Tạo Khóa Cho Ứng Dụng
- [SQLSERVER] Loại bỏ Restricted User trên database MSSQL
- [C#] Hướng dẫn tạo mã QRcode Style trên winform
- [C#] Hướng dẫn sử dụng temp mail service api trên winform
- [C#] Hướng dẫn tạo mã thanh toán VietQR Pay không sử dụng API trên winform
- [C#] Hướng Dẫn Tạo Windows Service Đơn Giản Bằng Topshelf
- [C#] Chia sẻ source code đọc dữ liệu từ Google Sheet trên winform
- [C#] Chia sẻ source code tạo mã QR MOMO đa năng Winform
- [C#] Chia sẻ source code phần mềm lên lịch tự động chạy ứng dụng Scheduler Task Winform
- [C#] Hướng dẫn download file từ Minio Server Winform
[C#] Hướng dẫn sử dụng thư viện Simple Broker (Observer pattern)
Xin chào các bạn, bài viết hôm nay mình sẽ giới thiệu đến các bạn thư viện Simple Broker thừa kế từ Observer pattern C#.
Vậy Observer pattern là gì?
Observer pattern là một mẫu thiết kế phần mềm mà một đối tượng, gọi là subject, duy trì một danh sách các thành phần phụ thuộc nó, gọi là observer, và thông báo tới chúng một cách tự động về bất cứ thay đổi nào, thường thì bằng cách gọi 1 hàm của chúng.
Giả sử chúng ta có một bảng tính excel với nhiều trang tính chứa các dữ liệu cần để thống kê. Ta có thể tạo ra vô số biểu đồ sử dụng dữ liệu ở các trang tính đó để hiển thị ra kết quả thống kê.
Khi ta thay đổi dữ liệu ở một trang tính, các biểu đồ có sử dụng dữ liệu đó cũng phải được cập nhật để có số liệu thống kê chính xác.
Ta có thể thấy là số lượng biểu đồ có thể dùng dữ liệu ở một trang tính là không giới hạn.
 
 
Và hướng giải quyết khi sử dụng Observer pattern: trang tính ở đây đóng vai trò là subject, còn các biểu đồ chính là các observer.
Mỗi khi trang tính được cập nhật dữ liệu, ta sẽ gọi cập nhật đến các biểu đồ phụ thuộc dữ liệu với trang tính đó.
Demo ứng dụng Observer pattern C#: (Sử dụng thư viện Simple Broker)

Source code Frm_main.cs:
using SimpleBroker;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Observer
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
            Load += Frm_Main_Load;
            Closed += Form_Main_Closed;
        }
        private void Form_Main_Closed(object sender, EventArgs e) => this.Unsubscribe<Message>();
        private void Frm_Main_Load(object sender, EventArgs e) => this.Subscribe<Message>(OnNext);
        private void OnNext(Message value) {
            txtLog.Text = $"{value.Source}, {value.Information} {Environment.NewLine} {txtLog.Text}";
        }
        public  class Message
        {
            public string Source { get; set; }
            public string Information { get; set; }
        }
        private void btn_Dispatcher_Click(object sender, EventArgs e) => new FormSendData().Show(this);
       
      
    }
}
Source code Frm_send_data C#:
using SimpleBroker;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Observer
{
    public partial class FormSendData : Form
    {
        public FormSendData()
        {
            InitializeComponent();
        }
        private void btn_send_Click(object sender, EventArgs e)
        {
            var message = new Frm_Main.Message
            {
                Source = txt_source.Text,
                Information = txt_information.Text
            };
            message.Publish();
        }
       
    }
}
Thanks for watching!

![[C#] Hướng dẫn sử dụng thư viện Simple Broker (Observer pattern)](https://laptrinhvb.net/uploads/users/9a8cb514e4428e85fb4ca07588e9103f.png)

![[C#] Sử dụng đệ quy để giải bài toán Tháp Hà Nội](https://laptrinhvb.net/uploads/source/csharp/thuattoan_thap_hanoi_csharp.gif)
![[C#] Hướng dẫn nối nhiều file PDF thành 1 file PDF](https://laptrinhvb.net/uploads/source/image_baiviet/42bc03a10d35047d17dab7425e386c14.jpg)
![[C#] Hướng dẫn viết ứng dụng ẩn và hiện Taskbar Windows](https://laptrinhvb.net/uploads/source/image_baiviet/ce1585bdf428bd1d3f0ae16de0a25b65.png)
![[C#] Chuyển đổi nhiều file hình ảnh thành một file PDF - sử dụng  PdfSharp library](https://laptrinhvb.net/uploads/source/csharp/convert_image_to_pdf_thumb.jpg)
![[C#] Hướng dẫn tạo Copyright Header trên từng file .cs trong Visual Studio](https://laptrinhvb.net/uploads/source/csharp/copyrightHeader_thumb.png)
![[C#] Import dữ liệu file Excel (xls, xlsx, csv) vào Dataset hoặc Datatable](https://laptrinhvb.net/uploads/source/image_baiviet/95dae3f410d40a147787f979ba5cc059.png)
![[C#] Hướng dẫn sử dụng Api v3 google để đăng bài tự động lên blogger, blogspot](https://laptrinhvb.net/uploads/source/image_baiviet/c4873ac823455e9f76265c74b38a36cd.png)
![[C#] Hướng dẫn cách bo tròn winform with Radius](https://laptrinhvb.net/uploads/source/csharp/border_radius_winform_csharp.png)
![[C#] Giới thiệu thư viện Autofac Dependency Injection](https://laptrinhvb.net/uploads/source/vbnet/autoface_csharp.jpg)
![[C#] Hướng dẫn sử dụng Delegate và Event trong lập trình Csharp](https://laptrinhvb.net/uploads/source/image_baiviet/d65b05ea1a3918d5545925edbc535b9b.png)
![[C#] Hướng dẫn lấy số điện thoại việt nam từ TextBox](https://laptrinhvb.net/uploads/source/csharp/find_phone_number_thumb.jpg)
![[C#] Hướng dẫn hiển thị bảng table ở giao diện Console](https://laptrinhvb.net/uploads/source/vbnet/table_console.jpg)
![[C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform](https://laptrinhvb.net/uploads/source/new_image_baiviet/microsoft-authenticator-cover.jpg)
![[C#] Invoke là gì? cách sử dụng phương thức Invoke()](https://laptrinhvb.net/uploads/source/csharp/animation_csharp_thumb.gif)
![[C#] Hướng dẫn tạo shortcut nhanh cho ứng dụng  đang chạy](https://laptrinhvb.net/uploads/source/csharp/short_cut_app_windows_thumb.png)
![[C#] Sử dụng Attribute Annotation trong lập trình C# CSharp](https://laptrinhvb.net/uploads/source/devexpress/su-dung-attribute-annotation-trong-lap-trinh-c-csharp-1594.jpg)
![[C#] Hướng dẫn LoadAsync PictureBox và Overlay trên Winform](https://laptrinhvb.net/uploads/source/csharp/overlay_picturebox.gif)




![[C#] 14 tỷ, 6 tháng lãi suất bao nhiêu tiền lãi? Hướng dẫn viết tool tính lãi xuất ngân hàng](https://laptrinhvb.net/uploads/source/vbnet/tinhlaisuat_nganhang.jpg)
![[C#] Hướng dẫn chuyển đổi tập tin hình ảnh XPS sang Bitmap](https://laptrinhvb.net/uploads/source/new_image_baiviet/convert_xps_bitmap_csharp.png)
![[C#] Hướng dẫn viết ứng dụng Scan QR code, barcode trực tiếp qua Webcam](https://laptrinhvb.net/uploads/source/csharp/scan_qrcode_realtime_thumb.png)
![[C#] Hướng dẫn viết ứng dụng liệt kê thông tin, xóa và khôi phục file và folder trong Recycle Bin Windows](https://laptrinhvb.net/uploads/source/image_baiviet/57c2dab865119c97df7b92ec904ad64d.png)
