示例#1
0
        public static IServiceCollection AddSimpleEsb(this IServiceCollection collection, Action <SimpleEsbBuilder> setupAction)
        {
            var builder = new SimpleEsbBuilder(collection);

            setupAction(builder);
            builder.Build();

            return(collection);
        }
示例#2
0
        public static void Main(string[] args)
        {
            simple.esb.mongo.MongoHelper.Register <Workflows.TrainModelsData>();
            simple.esb.mongo.MongoHelper.Register <PublishAgentState>();
            simple.esb.mongo.MongoHelper.Register <ImportData>();

            var host = new SimpleEsbBuilder()
                       .UseMongoDb("mongodb://192.168.1.111:27017", "simple_esb")
                       .UseRabbitMq("amqp://[email protected]:5672")
                       .RegisterHandlers(typeof(Program).GetTypeInfo().Assembly)
                       .BlocksWhileRunning()
                       .Build();

            host.Run();
        }
示例#3
0
        public static SimpleEsbBuilder RegisterHandlers(this SimpleEsbBuilder builder, Assembly assembly)
        {
            IServiceCollection services = builder.Services;

            foreach (Type type in assembly.GetTypes())
            {
                foreach (var handlerInterface in type.GetInterfaces().Where(MessageRouter.IsGenericHandler))
                {
                    Type[] genericArgs = handlerInterface.GetGenericArguments();
                    if (genericArgs.Length != 1)
                    {
                        // this is really more of an assert.
                        throw new InvalidOperationException("The IHandle<> interface contains more than one generic argument.");
                    }

                    services.AddTransient(handlerInterface, type);
                }
            }

            return(builder);
        }