Пример #1
0
        private static IKernel GetNinjectKernel()
        {
            var kernel = new StandardKernel();
            ExchangeConfiguration config = new ExchangeConfigurationProvider().Configuration;
            kernel.Bind<IBlogReader>()
                .To<DapperBlogRepository>();

            kernel.Bind<IAppSettingsHelper>()
                .To<AppSettingsHelper>();

            kernel.Bind<IPostOneWay<AddPostRequest>>()
                .To<AddPostRequestProcessor>()
                .WithConstructorArgument(config);

            kernel.Bind<IPostOneWay<AddCommentRequest>>()
                .To<AddCommentRequestProcessor>()
                .WithConstructorArgument(config);

            kernel.Bind<IDeleteOneWay<DeleteCommentRequest>>()
                .To<DeleteCommentRequestProcessor>()
                .WithConstructorArgument(config);

            kernel.Bind<IDeleteOneWay<DeletePostRequest>>()
                .To<DeletePostRequestProcessor>()
                .WithConstructorArgument(config);

            return kernel;
        }
Пример #2
0
        private static void Main(string[] args)
        {
            ExchangeConfiguration config = new ExchangeConfigurationProvider().Configuration;
            List<dynamic> consumers = new List<dynamic>(config.Routes.Count);
            try
            {
                foreach (var route in config.Routes)
                {
                    Type consumerType = typeof(Consumer<>);

                    Type generic = consumerType.MakeGenericType(route.Key);

                    Action<dynamic> action = x => OnAction(x);
                    object[] parameters = { config.ServerName, config.ExchangeType, route.Value, action };
                    dynamic consumer = Activator.CreateInstance(generic, parameters);
                    consumers.Add(consumer);
                    consumer.Open();

                }
                Console.WriteLine("Press <enter> to exit!");
                Console.ReadLine();
            }
            finally
            {
                foreach (var consumer in consumers)
                {
                    consumer.Close();
                }
            }
        }