IReliableCollection
或者我应该请求
IReliableStateManager
例如,如果我有一个在我的应用程序中广泛使用的字典,那么一次检索一次是否可以接受
RunAsync
方法,然后将此引用传递给需要它的任何方法,例如:
protected override async Task RunAsync(CancellationToken cancellationToken)
{
_someCollection = StateManager.GetOrAddAsync<IReliableDictionary<int, string>>(
"SomeName");
}
public async Task DoSomething(int id, string message)
{
_someClass.DoSomething(_someCollection, id, message);
}
public class SomeClass
{
public void DoSomething(IReliableDictionary<int, string> dict, int id, string msg)
{
using (ITransaction tx = StateManager.CreateTransaction())
{
await dict.AddAsync(tx, id, msg);
await tx.CommitAsync();
}
}
}
或者我应该请求
IReliableStateManager公司
在每次通话中,例如,
public class SomeClass
{
public void DoSomething(int id, string msg)
{
var dict = StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("SomeName");
using (ITransaction tx = StateManager.CreateTransaction())
{
await dict.AddAsync(tx, id, msg);
await tx.CommitAsync();
}
}
}
从我所知的情况来看,传递推荐信似乎很有效,但我不确定这是否会被视为不好的做法,我无法在报告中找到确切的答案
guidelines
documentation