简体   繁体   English

无界面访问谷物

[英]Access grain without interface

I'm planning my IoT system and comparing Akka.NET with Orleans. 我正在计划我的物联网系统,并将Akka.NET与Orleans进行比较。 Generally Orleans API is more close to .NET standards but I'm wondering is there any other way to communicate with Grain? 通常,奥尔良API更接近.NET标准,但我想知道还有其他与Grain进行通信的方法吗? In documentation I see that we define interface like 在文档中,我看到我们定义了接口

public interface IDevice : IGrainWithGuidKey
{
  Task TurnOn(TurnOnCommand command);
  Task TurnOff(TurnOffCommand command);
}

And use it like this 像这样使用

IDevice device = GrainFactory.GetGrain<IDevice>(id);

This is fine when we have actors that have very strict interface but in home we have a lot of devices and I don't want to define 100x interfaces for each of them. 当我们的演员具有非常严格的界面但在家里我们有很多设备并且我不想为每个设备定义100x接口时,这很好。 I would prefer to each of them have set of handlers for commands that it can handle and client could invoke 我希望他们每个人都有一套可以处理的命令处理程序,客户端可以调用这些处理程序

device.Execute(new TurnOnCommand()) 

without defining interface for each. 无需为每个接口定义接口。 Is this possible in Orleans? 在奥尔良有可能吗?

You can define an interface which accepts a base class/interface, such as ICommandProcessor<TCommand> and implement multiple versions of that, so you might have IMyDeviceGrain implementing ICommandProcessor<TurnOnCommand>, ICommandProcessor<TurnOffCommand> , and so on. 您可以定义一个接受基类/接口的接口,例如ICommandProcessor<TCommand>并实现该接口的多个版本,因此您可以让IMyDeviceGrain实现ICommandProcessor<TurnOnCommand>, ICommandProcessor<TurnOffCommand>等。

In that case, you might define ICommandProcessor<TCommand> as: 在这种情况下,可以将ICommandProcessor<TCommand>定义为:

public interface ICommandProcessor<TCommand>
{
    Task Process(TCommand command);   
}

The grain interface might look like: 谷物界面可能类似于:

public class IDeviceGrain :
  IGrainWithStringKey,
  ICommandProcessor<TurnOnCommand>,
  ICommandProcessor<TurnOffCommand>
{
}

The grain class could then look like: 谷物类如下所示:

public class DeviceGrain : Grain, IDeviceGrain
{
    Task Process(TurnOnCommand command) { /* turn on */ }
    Task Process(TurnOffCommand command) { /* turn off */ }
}

I've also seen people implement this by having a grain which has a single Task Process(object command) call which internally used dynamic to dispatch based on the type of command . 我还看到人们通过具有单个Task Process(object command)调用的谷物来实现此目的,该谷物在内部根据command类型在内部使用dynamic进行调度。

I hope that helps. 希望对您有所帮助。 Please let me know if there are any points which you would like clarified. 如果您有任何要澄清的地方,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到颗粒接口的实现 class - Cannot find an implementation class for grain interface 使用 Orleans 实现相同粒度接口的多个实现 - Multiple implementations of same grain interface using Orleans 找不到grain接口的实现类的类型代码 - Cannot find a type code for an implementation class for grain interface 通用接口/基类-无类型约束的访问成员 - Generic interface/base class - access members without type constraints 无需使用接口即可访问F#记录库属性 - Access to F# record base properties without using interface 以谷粒状态存储对谷粒实例的对象引用 - Store object reference to grain instance in grain state 如何指示Json.NET将接口类型转换为具体类型而无需访问序列化程序? - How can I instruct Json.NET to convert an interface type to a concrete type without access to the serializer? 如何在没有IDL或后期绑定调用远程处理方法的情况下访问CORBA接口 - How to access CORBA interface without IDL or late-bound invoke remoting methods 如何通过只有一个类型而不使用反射来访问一个类型实现的 static 抽象接口成员? - How to access a type's implemented static abstract interface members by having only a type without using reflection? 如何在IList中访问BinarySearch()方法以列出初始化而不会破坏程序到接口规则 - How to access BinarySearch() method in IList to List initialization without breaking program to interface rule
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM