我们如何访问有状态服务的 Controller 类中的 ParitionInfo 对象?这是该对象的链接:https : //docs.microsoft.com/en-us/dotnet/api/system.fabric.servicenotification.partitioninfo?view=azure-dotnetpublic class MyConntroller : ControllerBase{ [HttpPost] public async Task<IActionResult> Save(MyObject obj) { //Here I would like to access ParitionInfo object. How?! }}这是 ASP.NET Core 有状态服务中的服务定义,可以从定义它的基类轻松获取对象: /// <summary> /// The FabricRuntime creates an instance of this class for each service /// type instance. /// </summary> internal sealed class MyStatefulService : StatefulService { public MyStatefulService(StatefulServiceContext context) : base(context) { } /// <summary> /// Optional override to create listeners (like tcp, http) for this service instance. /// </summary> /// <returns>The collection of listeners.</returns> protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners() { return new ServiceReplicaListener[] { new ServiceReplicaListener(serviceContext => new KestrelCommunicationListener(serviceContext, (url, listener) => { ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}"); })) }; }我应该创建一个单例类,通过 DI 连接它,然后让 DI 框架将其实例传递给控制器类吗?是否有更好的捷径来实现访问 ParitionInfo 数据的目标?
- 1 回答
- 0 关注
- 160 浏览
添加回答
举报
0/150
提交
取消