HttpActorEndpoint(HttpClient client, JsonSerializerOptions serializer, ActorRouteMapping mapping, string id) { this.client = client; this.serializer = serializer; this.mapping = mapping; this.id = id; }
public static ActorRouteMapping From(Type @interface) { var query = typeof(ActorMessage <,>); var command = typeof(ActorMessage <>); Type ActorMessageInterface(Type t) => t.GetInterfaces().FirstOrDefault(x => x.IsGenericType && (x.GetGenericTypeDefinition() == command || x.GetGenericTypeDefinition() == query)); Type ActorMessageResult(Type t) { var message = ActorMessageInterface(t); return(message !.GetGenericTypeDefinition() == query ? message.GenericTypeArguments[1] : null); } bool IsActorMessage(Type t) { var message = ActorMessageInterface(t); return(message != null && message.GenericTypeArguments[0] == @interface); } var mapping = new ActorRouteMapping(@interface, @interface.FullName); var messages = @interface.Assembly.GetTypes().Where(IsActorMessage); foreach (var message in messages) { mapping.Register(message, message.FullName, ActorMessageResult(message)); } return(mapping); }
public void Register(ActorRouteMapping mapping) => actors.Add(mapping.Route.ToLowerInvariant(), mapping);