예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            var containerBuilder = new ContainerBuilder();

            containerBuilder.Populate(services);

            containerBuilder
            .Register(ctx => Configuration)
            .As <IConfigurationRoot>()
            .SingleInstance();

            containerBuilder
            .Register(ctx => RabbitConfig.Deserialize(ctx.Resolve <IConfigurationRoot>()))
            .SingleInstance();

            containerBuilder
            .RegisterType <RabbitConnectionFactory>()
            .As <IConnectionFactory>()
            .SingleInstance();

            containerBuilder
            .Register(ctx => new UTF8Encoding(false))
            .As <Encoding>()
            .SingleInstance();

            ApplicationContainer = containerBuilder.Build();

            return(new AutofacServiceProvider(ApplicationContainer));
        }
예제 #2
0
        public RabbitConnectionFactory(RabbitConfig rabbitConfig)
        {
            var cf = new ConnectionFactory()
            {
                HostName    = rabbitConfig.Hostname,
                Port        = rabbitConfig.Port,
                VirtualHost = rabbitConfig.VirtualHost,
                UserName    = rabbitConfig.Username,
                Password    = rabbitConfig.Password
            };

            cf.AutomaticRecoveryEnabled = true;

            var process = Assembly.GetEntryAssembly().GetName().Name;

            _connection = cf.CreateConnection(process);
        }