public static void AddMessageNet(this IApplicationBuilder app) { IMessageHost messageHost = app.ApplicationServices.GetRequiredService <IMessageHost>(); Option option = app.ApplicationServices.GetRequiredService <Option>(); messageHost.Register(option.Nodes.ToArray()); }
private static void RegisterRoutes(IMessageHost messageHost, object instance, MessageControllerAttribute classAttribute, Type type) { const string controllerText = "Controller"; IEnumerable <(MethodInfo MethodInfo, MessageEndpointAttribute?Attribute)> methods = type.GetMethods() .Select(x => (MethodInfo: x, Attribute: x.GetCustomAttribute <MessageEndpointAttribute>())) .Where(x => x.Attribute != null); foreach (var method in methods) { // Pattern = "[{method}]{path[/path...]}" string path = new[]
public static IApplicationBuilder MapMessageControllers(this IApplicationBuilder builder) { builder.VerifyNotNull(nameof(builder)); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); IMessageHost messageHost = builder.ApplicationServices.GetRequiredService <IMessageHost>(); foreach (var assembly in assemblies) { //Find assemblies with your ServiceType IEnumerable <(Type type, MessageControllerAttribute?attribute)> types = assembly.GetTypes() .Select(x => (type: x, attribute: x.GetCustomAttribute <MessageControllerAttribute>())) .Where(x => x.attribute != null); foreach (var type in types) { object instance = builder.ApplicationServices.GetRequiredService(type.type); RegisterRoutes(messageHost, instance, type.attribute !, type.type); } } return(builder); }
public MessageController(IMessageHost messageHost, ILogger <MessageController> logger) { _messageHost = messageHost; _logger = logger; }
public static void StartMessageHost(this IApplicationBuilder builder, string serviceId) { IMessageHost host = builder.ApplicationServices.GetRequiredService <IMessageHost>(); host.Start(serviceId); }