示例#1
0
        static async Task Main(string[] args)
        {
            await MySqlConnectionCheck.WaitForMySql(new TimeSpan(0, 1, 0)).ConfigureAwait(false);

            var container = new Container();

            container.Bootstrap();

            await ModulesHost.CreateDefaultBuilder(args)
            .UseSimpleInjector(container)
            .HostModule <ControllerModule>(options => options.Configure((sp) =>
            {
                using (var scope = sp.CreateScope())
                    scope.ServiceProvider.GetService <StateStoreContext>().Database.Migrate();
            }))

            .RunConsoleAsync().ConfigureAwait(false);
        }
示例#2
0
        static void Main(string[] args)
        {
            // RabbitMqConnectionCheck.WaitForRabbitMq(new TimeSpan(0, 1, 0)).Wait();
            MySqlConnectionCheck.WaitForMySql(new TimeSpan(0, 1, 0)).Wait();

            var container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            container.Collection.Register(typeof(IHandleMessages <>), typeof(Program).Assembly);

            container.Register(() =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <StateStoreContext>();
                optionsBuilder.UseMySql();
                return(new StateStoreContext(optionsBuilder.Options));
            }, Lifestyle.Scoped);

            container.ConfigureRebus(configurer => configurer
                                     .Transport(t => t.UseRabbitMq(RabbitMqConnectionCheck.ConnectionString, "Haipa.controller"))

                                     .Options(x =>
            {
                x.SimpleRetryStrategy();
                x.SetNumberOfWorkers(5);
            })
                                     .Sagas(sagas => sagas.StoreInMySql(MySqlConnectionCheck.ConnectionString, "Sagas", "SagaIndex"))
                                     .Timeouts(x => x.StoreInMySql(MySqlConnectionCheck.ConnectionString, "Timeouts"))
                                     .Serialization(x => x.UseNewtonsoftJson(new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.None
            }))
                                     .Logging(x => x.ColoredConsole(LogLevel.Debug)).Start());

            using (AsyncScopedLifestyle.BeginScope(container))
            {
                container.GetInstance <StateStoreContext>().Database.Migrate();
            }

            container.StartBus();

            Console.ReadLine();
        }