Example #1
0
        public static IContainer Run()
        {
            var builder = new ContainerBuilder();

            var mongoConnection = Config.MONGO_CONNECTION;
            var elkUrl          = Config.ELK_URL;
            var customerUrl     = Config.CUSTOMER_URL;

            if (string.IsNullOrEmpty(mongoConnection))
            {
                throw new Exception("The mongodb connection environment variable is missing.  Please check env variable MONGODB");
            }

            if (string.IsNullOrEmpty(elkUrl))
            {
                throw new Exception("The elk environment variable is missing.  Please check env variable ELK");
            }

            if (string.IsNullOrEmpty(customerUrl))
            {
                throw new Exception("The customer url environment variable is missing.  Please check env variable CUSTOMER_URL");
            }

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elkUrl))
            {
                IndexFormat          = "microexample-account-listener-{0:yyyy.MM}",
                MinimumLogEventLevel = Serilog.Events.LogEventLevel.Information
            })
                         .WriteTo.Console()
                         .CreateLogger();

            builder.RegisterModule(new ServiceProxyModule(customerUrl));
            builder.RegisterModule(new RepositoryModule(mongoConnection));
            builder.RegisterModule(new ApplicationModule());
            builder.RegisterModule(new LoggingModule());

            builder.RegisterType <NewCustomerEventProcessor>().AsSelf().AsImplementedInterfaces();

            //build even maps
            builder.Register <EventProcessorMap>(c =>
            {
                var eventMaps = new EventProcessorMap();

                eventMaps.Add("Customer.Created", c.Resolve <NewCustomerEventProcessor>());

                return(eventMaps);
            });

            builder.RegisterType <EventProcessor>().As <IEventProcessor>()
            .WithParameter("brokerUrl", Config.BROKER_URL);

            return(builder.Build());
        }
        public static IContainer Run()
        {
            var builder = new ContainerBuilder();

            var sqlConnection = Config.SqlConnection;
            var elkUrl        = Config.ELK_URL;

            if (string.IsNullOrEmpty(sqlConnection))
            {
                throw new Exception("The sql connection environment variable is missing.  Please check env variable SQL_CONNECTION");
            }

            if (string.IsNullOrEmpty(elkUrl))
            {
                throw new Exception("The elk environment variable is missing.  Please check env variable ELK");
            }

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elkUrl))
            {
                IndexFormat          = "microexample-accountview-listener-{0:yyyy.MM}",
                MinimumLogEventLevel = Serilog.Events.LogEventLevel.Information
            })
                         .WriteTo.Console()
                         .CreateLogger();

            var optionsBuilder = new DbContextOptionsBuilder <AccountViewContext>();

            optionsBuilder.UseSqlServer(sqlConnection);

            builder.RegisterType <SerilogAdapter>().As <ILog>();

            builder.RegisterType <NewCustomerEventProcessor>().AsSelf().AsImplementedInterfaces();

            builder.RegisterType <AccountViewDbContextFactory>().As <IAccountViewContextFactory>().WithParameter("options", optionsBuilder.Options);

            //build even maps
            builder.Register <EventProcessorMap>(c =>
            {
                var eventMaps = new EventProcessorMap();

                eventMaps.Add("Customer.Created", c.Resolve <NewCustomerEventProcessor>());

                return(eventMaps);
            });

            builder.RegisterType <EventProcessor>().As <IEventProcessor>()
            .WithParameter("brokerUrl", Config.BROKER_URL);

            return(builder.Build());
        }