Ejemplo n.º 1
0
        public static IRepositoryBuilder BuildInMemoryRepository(this IRepositoryBuilder repositoryBuilder,
                                                                 InitialData initialData, InMemoryIndex initialIndex)
        {
            if (initialData == null)
            {
                throw new ArgumentNullException(nameof(initialData));
            }
            if (initialIndex == null)
            {
                throw new ArgumentNullException(nameof(initialIndex));
            }

            // Precedence: if a service is registered in the collection, use that
            // instead of creating instances locally.
            var services = (repositoryBuilder as RepositoryBuilder)?.Services;

            if (services?.GetService <DataProvider>() is InMemoryDataProvider dataProvider)
            {
                // If there is an instance in the container, use that. We have to set
                // these instances manually instead of using the extension method so that
                // we do not overwrite the store instance.
                Providers.Instance.DataProvider = dataProvider;
                Providers.Instance.DataStore    = services.GetService <IDataStore>();
            }
            else
            {
                dataProvider = new InMemoryDataProvider();
                repositoryBuilder.UseDataProvider(dataProvider);
            }

            Providers.Instance.ResetBlobProviders();

            var searchEngine = services?.GetService <ISearchEngine>() ?? new InMemorySearchEngine(initialIndex);

            repositoryBuilder
            .UseLogger(new DebugWriteLoggerAdapter())
            .UseTracer(new SnDebugViewTracer())
            .UseInitialData(initialData)
            .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
            .UseExclusiveLockDataProviderExtension(new InMemoryExclusiveLockDataProvider())
            .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
            .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
            .AddBlobProvider(new InMemoryBlobProvider())
            .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
            .UsePackagingDataProviderExtension(new InMemoryPackageStorageProvider())
            .UseSearchEngine(searchEngine)
            .UseSecurityDataProvider(GetSecurityDataProvider(dataProvider))
            .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
            .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
            .StartWorkflowEngine(false);

            var statDp = services?.GetService <IStatisticalDataProvider>() as InMemoryStatisticalDataProvider
                         ?? new InMemoryStatisticalDataProvider();

            repositoryBuilder.UseStatisticalDataProvider(statDp);

            Providers.Instance.PropertyCollector = new EventPropertyCollector();

            return(repositoryBuilder);
        }