DataHubV1 1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DataHubV1 --version 1.0.3
NuGet\Install-Package DataHubV1 -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DataHubV1" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DataHubV1 --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DataHubV1, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DataHubV1 as a Cake Addin #addin nuget:?package=DataHubV1&version=1.0.3 // Install DataHubV1 as a Cake Tool #tool nuget:?package=DataHubV1&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DataHub Library
데이터 통신 및 상태 관리를 위한 간단하고 유연한 라이브러리입니다.
주요 기능
- Thread-safe한 데이터 저장 및 조회
- 비동기 데이터 대기 지원
- 일회성/영구성 데이터 접근 방식
- 타입 기반 데이터 처리
- 비동기 이벤트 알림 시스템
기본 사용 방법
1. 데이터 정의
// 공유할 데이터 클래스 정의
public record TestResult(bool IsPass, string Message);
2. 기본적인 데이터 저장 및 조회
// 데이터 스코프 획득
var scope = DataHub.GetScope<TestResult>();
// 데이터 저장
scope.Set("test1", new TestResult(IsPass: true, Message: "성공"));
// 일회성 데이터 조회 (조회 후 삭제됨)
var result = scope.Get<TestResult>("test1");
Console.WriteLine($"테스트 결과: {result?.IsPass}");
// 영구성 데이터 조회 (데이터 유지됨)
var persistentResult = scope.Peek<TestResult>("test1");
3. 비동기 데이터 대기
async Task WaitForResultAsync()
{
var scope = DataHub.GetScope<TestResult>();
// 특정 키의 데이터를 대기
var result = await scope.GetAwait<TestResult>("test2");
// 타입 기반 대기 (키를 모르는 경우)
var typedResult = await scope.GetAwait<TestResult>();
Console.WriteLine($"받은 데이터: {typedResult.Key} = {typedResult.Value.Message}");
}
4. 데이터 변경 알림 구독
// 알림 처리기 구현
public class TestResultNotification : IDataNotification<TestResult>
{
public void OnDataChanged(string key, TestResult value)
{
Console.WriteLine($"데이터 변경: {key}, 결과 = {value.IsPass}");
}
}
// 알림 구독
var scope = DataHub.GetScope<TestResult>();
var notification = new TestResultNotification();
scope.RegisterNotification(notification);
// 알림 해제
scope.UnregisterNotification(notification);
고급 사용 예제
1. 취소 토큰을 사용한 대기 작업
async Task WaitWithTimeoutAsync()
{
var scope = DataHub.GetScope<TestResult>();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
try
{
var result = await scope.GetAwait<TestResult>("test3", cts.Token);
}
catch (OperationCanceledException)
{
Console.WriteLine("대기 시간 초과");
}
}
2. 여러 타입의 데이터 처리
public record LogEntry(string Message, DateTime Timestamp);
public record MetricData(string Name, double Value);
async Task ProcessMultipleTypesAsync()
{
var logScope = DataHub.GetScope<LogEntry>();
var metricScope = DataHub.GetScope<MetricData>();
// 각각의 스코프는 독립적으로 동작
logScope.Set("log1", new LogEntry("시스템 시작", DateTime.Now));
metricScope.Set("metric1", new MetricData("CPU", 75.5));
}
주의사항
- Get 메서드로 조회한 데이터는 저장소에서 즉시 삭제됩니다.
- Peek 메서드는 데이터를 유지하면서 조회합니다.
- GetAwait/PeekAwait는 데이터가 없는 경우 저장될 때까지 대기합니다.
- 알림 처리는 비동기적으로 수행되며, 실패 시 자동으로 재시도됩니다.
Thread Safety
모든 작업은 Thread-safe하게 구현되어 있어 멀티스레드 환경에서 안전하게 사용할 수 있습니다.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.