访问Azure Service Fabric状态服务状态 [英] Access Azure Service Fabric stateful service state

查看:103
本文介绍了访问Azure Service Fabric状态服务状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将WebAPI添加到我的有状态服务中,并希望从中访问StateManager(从StatefulService类实现之外).

I have added WebAPI to my stateful serive and want to access StateManager from it (from outside of StatefulService class implementation).

最好的方法是什么?

目前,我正在为此使用一个小类:

Currently I am using a small class for this:

internal static class InstanceAccessor
{
   internal static StatefulService ActiveInstance { get; set; }
}

并将值放在StatefulService的RunAsync方法中:

And put the value inside RunAsync method of the StatefulService :

protected override async Task RunAsync(CancellationToken cancellationToken)
{
    InstanceAccessor.ActiveInstance = this;
    ...

推荐答案

There's a sample project on Github that shows a simple way to do it using dependency injection.

这篇关于访问Azure Service Fabric状态服务状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆