Beispiel #1
0
        public void ConfigureContainer(ContainerBuilder containerBuilder)
        {
            var cqrsAssembly = typeof(Startup).Assembly;

            this.SQLiteTestConfigurationBuilder = new SQLiteTestConfigurationBuilder();
            var migrator = new FluentDbMigrator(
                DbProviderNames.SQLite,
                this.SQLiteTestConfigurationBuilder.ConnectionString,
                typeof(M0_Baseline).Assembly);

            migrator.Migrate();

            using (var connection = new SQLiteConnection(this.SQLiteTestConfigurationBuilder.ConnectionString))
            {
                connection.Open();
                connection.BoostSQLiteInsertions();

                var json = typeof(Startup).Assembly.GetResourceText(".dbdata.json", true);

                var dbSerializer = DbUtils.GetUtilityFactory(DbProviderNames.SQLite).CreateDbSerializer(connection);
                dbSerializer.DeserializeDbData(json);
            }

            containerBuilder
            .AddCqrs(cqrsAssembly, typeof(TransactionalCommandHandlerDecorator <>))
            .AddNHibernate(
                this.SQLiteTestConfigurationBuilder.Configuration,
                typeof(Startup).Assembly,
                typeof(SQLiteIdUserType <>));

            containerBuilder
            .RegisterAssemblyTypes(typeof(Startup).Assembly)
            .Where(t => t.FullName.EndsWith("Repository"))
            .AsImplementedInterfaces()
            .InstancePerLifetimeScope();

            this.ConfigureMessaging(containerBuilder);

            containerBuilder
            .RegisterInstance(this)
            .As <IAutofacStartup>()
            .SingleInstance();
        }