public void Dispose()
        {
            try
            {
                // Ensure LocalDb databases are deleted after use so that LocalDb doesn't throw if
                // the temp location in which they are stored is later cleaned.
                using (var context = new EFReviewRepository(_databaseName))
                {
                    context.Database.Delete();
                }

                _Service.Dispose();
            }
            finally
            {
                AppDomain.CurrentDomain.SetData("DataDirectory", _previousDataDirectory);
            }
        }
        public override void Publish(string dbconnection, string data, bool sample, bool reduced, string strategy = SqlDbConfiguration.SqlAzureExecutionStrategy)
		{
			base.Publish(dbconnection, data, sample, reduced, strategy);
			string connection = dbconnection;
			SafeWriteDebug("ConnectionString: " + connection);

			using (var db = new EFReviewRepository(connection))
			{
				if (sample)
				{
					SafeWriteVerbose("Running sample scripts");
					new SqlReviewSampleDatabaseInitializer().InitializeDatabase(db);
				}
				else
				{
					SafeWriteVerbose("Running minimum scripts");
					new SetupMigrateDatabaseToLatestVersion<EFReviewRepository, Configuration>().InitializeDatabase(db);
				}
			}
		}
        private UnityContainer GetLocalContainer(SearchConnection searchConnection, string connectionString)
        {
            var container = new UnityContainer();
            container.RegisterType<IKnownSerializationTypes, CatalogEntityFactory>("catalog", new ContainerControlledLifetimeManager());
            container.RegisterInstance<IConsumerFactory>(new DomainAssemblyScannerConsumerFactory(container));
            container.RegisterType<IKnownSerializationTypes, DomainAssemblyScannerConsumerFactory>("scaned", new ContainerControlledLifetimeManager(), new InjectionConstructor(container));
            container.RegisterType<IConsumerFactory, DomainAssemblyScannerConsumerFactory>();
            container.RegisterType<IEngineProcess, SingleThreadConsumingProcess>();
            container.RegisterType<IMessageSerializer, DataContractMessageSerializer>();
            container.RegisterType<IQueueWriter, InMemoryQueueWriter>();
            container.RegisterType<IQueueReader, InMemoryQueueReader>();
            container.RegisterType<IMessageSender, DefaultMessageSender>(new ContainerControlledLifetimeManager());
            container.RegisterType<ICatalogEntityFactory, CatalogEntityFactory>(new ContainerControlledLifetimeManager());
            container.RegisterType<IReviewEntityFactory, ReviewEntityFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType<ICatalogService, CatalogService>();
            container.RegisterType<ISearchIndexBuilder, CatalogItemIndexBuilder>("catalogitem");
            container.RegisterType<ILogOperationFactory, LogOperationFactory>();
            container.RegisterType<ISearchEntityFactory, SearchEntityFactory>(new ContainerControlledLifetimeManager());
            container.RegisterType<ISearchIndexController, SearchIndexController>();
            container.RegisterType<ICacheRepository, HttpCacheRepository>();

            if (string.Equals(searchConnection.Provider, SearchProviders.Lucene.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                // Lucene Search implementation
                container.RegisterType<ISearchProvider, LuceneSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, LuceneSearchQueryBuilder>();
            }
            else
            {
                container.RegisterType<ISearchProvider, ElasticSearchProvider>();
                container.RegisterType<ISearchQueryBuilder, ElasticSearchQueryBuilder>();
            }


            // register instances here
            container.RegisterInstance<ISearchConnection>(searchConnection);

            var catalogRepository = new EFCatalogRepository(connectionString);
            container.RegisterInstance<ICatalogRepository>(catalogRepository);
            container.RegisterType<ICatalogOutlineBuilder, CatalogOutlineBuilder>();
            container.RegisterInstance<IPricelistRepository>(catalogRepository);
            container.RegisterInstance<IOperationLogRepository>(new OperationLogContext(connectionString));
            container.RegisterInstance<IBuildSettingsRepository>(new EFSearchRepository(connectionString));

            var reviewRepository = new EFReviewRepository(connectionString);
            container.RegisterInstance<IReviewRepository>(reviewRepository);


            var indexingProgress = new ProgressRecord(1, "Indexing Progress", "Progress:");
            var observer = new ProgressObserver(this, indexingProgress);
            container.RegisterInstance<ISystemObserver>(observer);

            return container;
        }