Exemplo n.º 1
0
        public static ConsumerMetaData Create(Type type)
        {
            var meta = new ConsumerMetaData {
                ConsumerType = type
            };
            var att = type.GetCustomAttributes(typeof(QueueAttribute), true).FirstOrDefault();

            meta.QueueNameTemplate = att == null ? "{DefaultQueue}" : ((QueueAttribute)att).NameTemplate;

            return(meta);
        }
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterAssemblyTypes(_consumerAssemblies)
            .Where(x => typeof(IConsumer).IsAssignableFrom(x))
            .WithMetadata(x => ConsumerMetaData.Create(x).ToKeyValuePairs())
            .AsSelf()
            .AsImplementedInterfaces();

            builder.RegisterType <RabbitMqBusFactory>().As <IRabbitMqBusFactory>().SingleInstance();

            builder.RegisterConfigSettings <IBusSettings>();

            builder.RegisterType <QueueNameParser>().As <IQueueNameParser>().SingleInstance();

            builder.Register(x => x.Resolve <IRabbitMqBusFactory>().Bus)
            .As <IBusControl>()
            .As <IBus>();
        }