コード例 #1
0
        public static void AddMessageNet(this IApplicationBuilder app)
        {
            IMessageHost messageHost = app.ApplicationServices.GetRequiredService <IMessageHost>();
            Option       option      = app.ApplicationServices.GetRequiredService <Option>();

            messageHost.Register(option.Nodes.ToArray());
        }
コード例 #2
0
ファイル: HostExtensions.cs プロジェクト: khooversoft/Spin
        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[]
コード例 #3
0
ファイル: HostExtensions.cs プロジェクト: khooversoft/Spin
        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);
        }
コード例 #4
0
ファイル: MessageController.cs プロジェクト: khooversoft/Spin
 public MessageController(IMessageHost messageHost, ILogger <MessageController> logger)
 {
     _messageHost = messageHost;
     _logger      = logger;
 }
コード例 #5
0
ファイル: HostExtensions.cs プロジェクト: khooversoft/Spin
        public static void StartMessageHost(this IApplicationBuilder builder, string serviceId)
        {
            IMessageHost host = builder.ApplicationServices.GetRequiredService <IMessageHost>();

            host.Start(serviceId);
        }