man-group / dapr-sidekick-dotnet

Dapr Sidekick for .NET - a lightweight lifetime management component for Dapr
Apache License 2.0
177 stars 21 forks source link

Are there an extension methods like GetStateAsync<T> ? #46

Closed StefH closed 2 years ago

StefH commented 2 years ago

The original / official Dapr .NET SDK has support for getting a state key like:

var counter = await daprClient.GetStateAsync<int>(StoreName, Key);

Is there also something defined in this project?


Currently I'm using this code to get a state value:

var counterAsString = await sidekick
            .HttpClientFactory
            .CreateDaprHttpClient().GetStringAsync($"http://localhost:3500/v1.0/state/{StoreName}/{key}");
var counter = int.TryParse(counterAsString, out var c) ? c: 0;
logger.Log(DaprLogLevel.Information, "counter = {0}", counter);
badgeratu commented 2 years ago

The goal of Dapr Sidekick is to complement the official Dapr .NET SDK, and focuses on managing the Dapr sidecar lifecycle. While we have made a similar Service Invocation interface available for non .NET Core platforms. there's no plans to duplicate any further functionality of the official SDK. If you are running on .NET Core your first example of using daprClient.GetStateAsync should work just fine with the sidecar launched by Sidekick. If you are running on .NET Framework, your best bet is probably making a request to the Dapr SDK team to also support .NET Framework.

StefH commented 2 years ago

The official Dapr .NET SDK (https://github.com/dapr/dotnet-sdk) does already support GetStateAsync, so I was using that in my first code example.

However, I'm also investigating if I can switch from the official Dapr .NET SDK to this project (mostly because using this project I can just run my code in Visual Studio + Debug, where with the official Dapr SDK I need to start it using CLI)

So I was thinking of building my own extensions to support the same easy interface e.g. GetStateAsync and actually I was wondering if I can create a new C# Project under this repository and then also release a NuGet package for that.

badgeratu commented 2 years ago

If you are already using the Dapr .NET SDK though it's not an either/or question, Sidekick is designed to complement the official SDK and the SDK methods should automatically work with the sidecar launched & managed by Sidekick. There shouldn't be a need to add another package to this solution, just add the Dapr .NET SDK to your project which is currently using Sidekick and it should "just work". You can see this in action in our Actor sample.

StefH commented 2 years ago

Thank you for your help.

StefH commented 2 years ago

Thank you for your help.