Browse Source

Remove support for other mongodb engines.

pull/397/head
Sebastian 7 years ago
parent
commit
a2d003423d
  1. 58
      src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs
  2. 4
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs
  3. 4
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  4. 32
      src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs
  5. 25
      src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs
  6. 15
      src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs
  7. 10
      src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs
  8. 53
      src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs
  9. 25
      src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs
  10. 4
      src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs
  11. 15
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbEngine.cs
  12. 24
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs
  13. 16
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs
  14. 4
      src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs
  15. 4
      src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs
  16. 2
      src/Squidex/Config/Domain/EventStoreServices.cs
  17. 3
      src/Squidex/Config/Domain/StoreServices.cs
  18. 6
      src/Squidex/appsettings.json
  19. 2
      tests/Squidex.Infrastructure.Tests/EventSourcing/MongoEventStoreFixture.cs

58
src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs

@ -24,8 +24,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
{ {
public sealed partial class MongoAssetRepository : MongoRepositoryBase<MongoAssetEntity>, IAssetRepository public sealed partial class MongoAssetRepository : MongoRepositoryBase<MongoAssetEntity>, IAssetRepository
{ {
public MongoAssetRepository(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoAssetRepository(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }
@ -36,40 +36,26 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
protected override Task SetupCollectionAsync(IMongoCollection<MongoAssetEntity> collection, CancellationToken ct = default) protected override Task SetupCollectionAsync(IMongoCollection<MongoAssetEntity> collection, CancellationToken ct = default)
{ {
return collection.Indexes.CreateManyAsync( return collection.Indexes.CreateManyAsync(new[]
new[] {
{ new CreateIndexModel<MongoAssetEntity>(
new CreateIndexModel<MongoAssetEntity>( Index
Index .Ascending(x => x.AppId)
.Ascending(x => x.AppId) .Ascending(x => x.IsDeleted)
.Ascending(x => x.IsDeleted) .Ascending(x => x.FileName)
.Ascending(x => x.FileName) .Ascending(x => x.Tags)
.Ascending(x => x.Tags) .Descending(x => x.LastModified)),
.Descending(x => x.LastModified), new CreateIndexModel<MongoAssetEntity>(
new CreateIndexOptions Index
{ .Ascending(x => x.AppId)
Name = Options.IsDocumentDb ? "FileName_Tags" : null .Ascending(x => x.IsDeleted)
}), .Ascending(x => x.FileHash)),
new CreateIndexModel<MongoAssetEntity>( new CreateIndexModel<MongoAssetEntity>(
Index Index
.Ascending(x => x.AppId) .Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted) .Ascending(x => x.IsDeleted)
.Ascending(x => x.FileHash), .Ascending(x => x.Slug))
new CreateIndexOptions }, ct);
{
Name = Options.IsDocumentDb ? "FileHash" : null
}),
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.Slug),
new CreateIndexOptions
{
Name = Options.IsDocumentDb ? "Slug" : null
})
},
ct);
} }
public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, ClrQuery query) public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, ClrQuery query)

4
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs

@ -34,8 +34,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
private readonly IAppProvider appProvider; private readonly IAppProvider appProvider;
private readonly IJsonSerializer serializer; private readonly IJsonSerializer serializer;
public MongoContentCollection(IMongoDatabase database, IOptions<MongoDbOptions> options, IJsonSerializer serializer, IAppProvider appProvider) public MongoContentCollection(IMongoDatabase database, IJsonSerializer serializer, IAppProvider appProvider)
: base(database, options) : base(database)
{ {
this.appProvider = appProvider; this.appProvider = appProvider;

4
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -43,7 +43,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
StatusSerializer.Register(); StatusSerializer.Register();
} }
public MongoContentRepository(IMongoDatabase database, IOptions<MongoDbOptions> options, IAppProvider appProvider, IJsonSerializer serializer, ITextIndexer indexer, TypeNameRegistry typeNameRegistry) public MongoContentRepository(IMongoDatabase database, IAppProvider appProvider, IJsonSerializer serializer, ITextIndexer indexer, TypeNameRegistry typeNameRegistry)
{ {
Guard.NotNull(appProvider, nameof(appProvider)); Guard.NotNull(appProvider, nameof(appProvider));
Guard.NotNull(database, nameof(database)); Guard.NotNull(database, nameof(database));
@ -59,7 +59,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
typeAssetDeleted = typeNameRegistry.GetName<AssetDeleted>(); typeAssetDeleted = typeNameRegistry.GetName<AssetDeleted>();
typeContentDeleted = typeNameRegistry.GetName<ContentDeleted>(); typeContentDeleted = typeNameRegistry.GetName<ContentDeleted>();
contents = new MongoContentCollection(database, options, serializer, appProvider); contents = new MongoContentCollection(database, serializer, appProvider);
} }
public Task InitializeAsync(CancellationToken ct = default) public Task InitializeAsync(CancellationToken ct = default)

32
src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs

@ -19,8 +19,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.History
{ {
public class MongoHistoryEventRepository : MongoRepositoryBase<HistoryEvent>, IHistoryEventRepository public class MongoHistoryEventRepository : MongoRepositoryBase<HistoryEvent>, IHistoryEventRepository
{ {
public MongoHistoryEventRepository(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoHistoryEventRepository(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }
@ -31,18 +31,22 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.History
protected override Task SetupCollectionAsync(IMongoCollection<HistoryEvent> collection, CancellationToken ct = default) protected override Task SetupCollectionAsync(IMongoCollection<HistoryEvent> collection, CancellationToken ct = default)
{ {
return collection.Indexes.CreateManyAsync( return collection.Indexes.CreateManyAsync(new[]
new[] {
{ new CreateIndexModel<HistoryEvent>(
new CreateIndexModel<HistoryEvent>( Index
Index .Ascending(x => x.AppId)
.Ascending(x => x.AppId) .Ascending(x => x.Channel)
.Ascending(x => x.Channel) .Descending(x => x.Created)
.Descending(x => x.Created) .Descending(x => x.Version)),
.Descending(x => x.Version)), new CreateIndexModel<HistoryEvent>(
new CreateIndexModel<HistoryEvent>(Index.Ascending(x => x.Created), Index
new CreateIndexOptions { ExpireAfter = TimeSpan.FromDays(365) }) .Ascending(x => x.Created),
}, ct); new CreateIndexOptions
{
ExpireAfter = TimeSpan.FromDays(365)
})
}, ct);
} }
public async Task<IReadOnlyList<HistoryEvent>> QueryByChannelAsync(Guid appId, string channelPrefix, int count) public async Task<IReadOnlyList<HistoryEvent>> QueryByChannelAsync(Guid appId, string channelPrefix, int count)

25
src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs

@ -23,8 +23,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules
{ {
public sealed class MongoRuleEventRepository : MongoRepositoryBase<MongoRuleEventEntity>, IRuleEventRepository public sealed class MongoRuleEventRepository : MongoRepositoryBase<MongoRuleEventEntity>, IRuleEventRepository
{ {
public MongoRuleEventRepository(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoRuleEventRepository(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }
@ -33,15 +33,20 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules
return "RuleEvents"; return "RuleEvents";
} }
protected override async Task SetupCollectionAsync(IMongoCollection<MongoRuleEventEntity> collection, CancellationToken ct = default) protected override Task SetupCollectionAsync(IMongoCollection<MongoRuleEventEntity> collection, CancellationToken ct = default)
{ {
await collection.Indexes.CreateManyAsync( return collection.Indexes.CreateManyAsync(new[]
new[] {
{ new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.NextAttempt)),
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.NextAttempt)), new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.AppId).Descending(x => x.Created)),
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.AppId).Descending(x => x.Created)), new CreateIndexModel<MongoRuleEventEntity>(
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.Expires), new CreateIndexOptions { ExpireAfter = TimeSpan.Zero }) Index
}, ct); .Ascending(x => x.Expires),
new CreateIndexOptions
{
ExpireAfter = TimeSpan.Zero
})
}, ct);
} }
public Task QueryPendingAsync(Instant now, Func<IRuleEventEntity, Task> callback, CancellationToken ct = default) public Task QueryPendingAsync(Instant now, Func<IRuleEventEntity, Task> callback, CancellationToken ct = default)

15
src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs

@ -31,8 +31,8 @@ namespace Squidex.Domain.Users.MongoDb.Infrastructure
}); });
} }
public MongoPersistedGrantStore(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoPersistedGrantStore(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }
@ -43,12 +43,11 @@ namespace Squidex.Domain.Users.MongoDb.Infrastructure
protected override Task SetupCollectionAsync(IMongoCollection<PersistedGrant> collection, CancellationToken ct = default) protected override Task SetupCollectionAsync(IMongoCollection<PersistedGrant> collection, CancellationToken ct = default)
{ {
return collection.Indexes.CreateManyAsync( return collection.Indexes.CreateManyAsync(new[]
new[] {
{ new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.ClientId)),
new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.ClientId)), new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.SubjectId))
new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.SubjectId)) }, ct);
}, ct);
} }
public Task StoreAsync(PersistedGrant grant) public Task StoreAsync(PersistedGrant grant)

10
src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs

@ -31,8 +31,8 @@ namespace Squidex.Domain.Users.MongoDb
}); });
} }
public MongoRoleStore(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoRoleStore(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }
@ -41,17 +41,11 @@ namespace Squidex.Domain.Users.MongoDb
return "Identity_Roles"; return "Identity_Roles";
} }
protected override string ShardKey()
{
return "Shard";
}
protected override Task SetupCollectionAsync(IMongoCollection<IdentityRole> collection, CancellationToken ct = default) protected override Task SetupCollectionAsync(IMongoCollection<IdentityRole> collection, CancellationToken ct = default)
{ {
return collection.Indexes.CreateOneAsync( return collection.Indexes.CreateOneAsync(
new CreateIndexModel<IdentityRole>( new CreateIndexModel<IdentityRole>(
Index Index
.Ascending("Shard")
.Ascending(x => x.NormalizedName), .Ascending(x => x.NormalizedName),
new CreateIndexOptions new CreateIndexOptions
{ {

53
src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs

@ -105,8 +105,8 @@ namespace Squidex.Domain.Users.MongoDb
}); });
} }
public MongoUserStore(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoUserStore(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }
@ -115,36 +115,29 @@ namespace Squidex.Domain.Users.MongoDb
return "Identity_Users"; return "Identity_Users";
} }
protected override string ShardKey()
{
return "Shard";
}
protected override Task SetupCollectionAsync(IMongoCollection<MongoUser> collection, CancellationToken ct = default) protected override Task SetupCollectionAsync(IMongoCollection<MongoUser> collection, CancellationToken ct = default)
{ {
return collection.Indexes.CreateManyAsync( return collection.Indexes.CreateManyAsync(new[]
new[] {
{ new CreateIndexModel<MongoUser>(
Options.IsDocumentDb ? Index
new CreateIndexModel<MongoUser>(Index.Ascending("Logins.LoginProvider")) : .Ascending("Logins.LoginProvider")
new CreateIndexModel<MongoUser>(Index.Ascending("Logins.LoginProvider").Ascending("Logins.ProviderKey")), .Ascending("Logins.ProviderKey")),
new CreateIndexModel<MongoUser>( new CreateIndexModel<MongoUser>(
Index Index
.Ascending("Shard") .Ascending(x => x.NormalizedUserName),
.Ascending(x => x.NormalizedUserName), new CreateIndexOptions
new CreateIndexOptions {
{ Unique = true
Unique = true }),
}), new CreateIndexModel<MongoUser>(
new CreateIndexModel<MongoUser>( Index
Index .Ascending(x => x.NormalizedEmail),
.Ascending("Shard") new CreateIndexOptions
.Ascending(x => x.NormalizedEmail), {
new CreateIndexOptions Unique = true
{ })
Unique = true }, ct);
})
}, ct);
} }
protected override MongoCollectionSettings CollectionSettings() protected override MongoCollectionSettings CollectionSettings()

25
src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs

@ -27,8 +27,8 @@ namespace Squidex.Infrastructure.EventSourcing
get { return Database.GetCollection<BsonDocument>(CollectionName()); } get { return Database.GetCollection<BsonDocument>(CollectionName()); }
} }
public MongoEventStore(IMongoDatabase database, IOptions<MongoDbOptions> options, IEventNotifier notifier) public MongoEventStore(IMongoDatabase database, IEventNotifier notifier)
: base(database, options) : base(database)
{ {
Guard.NotNull(notifier, nameof(notifier)); Guard.NotNull(notifier, nameof(notifier));
@ -47,12 +47,21 @@ namespace Squidex.Infrastructure.EventSourcing
protected override Task SetupCollectionAsync(IMongoCollection<MongoEventCommit> collection, CancellationToken ct = default) protected override Task SetupCollectionAsync(IMongoCollection<MongoEventCommit> collection, CancellationToken ct = default)
{ {
return collection.Indexes.CreateManyAsync( return collection.Indexes.CreateManyAsync(new[]
new[] {
{ new CreateIndexModel<MongoEventCommit>(
new CreateIndexModel<MongoEventCommit>(Index.Ascending(x => x.Timestamp).Ascending(x => x.EventStream)), Index
new CreateIndexModel<MongoEventCommit>(Index.Ascending(x => x.EventStream).Descending(x => x.EventStreamOffset), new CreateIndexOptions { Unique = true }) .Ascending(x => x.Timestamp)
}, ct); .Ascending(x => x.EventStream)),
new CreateIndexModel<MongoEventCommit>(
Index
.Ascending(x => x.EventStream)
.Descending(x => x.EventStreamOffset),
new CreateIndexOptions
{
Unique = true
})
}, ct);
} }
} }
} }

4
src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs

@ -17,8 +17,8 @@ namespace Squidex.Infrastructure.Migrations
private const string DefaultId = "Default"; private const string DefaultId = "Default";
private static readonly FindOneAndUpdateOptions<MongoMigrationEntity> UpsertFind = new FindOneAndUpdateOptions<MongoMigrationEntity> { IsUpsert = true }; private static readonly FindOneAndUpdateOptions<MongoMigrationEntity> UpsertFind = new FindOneAndUpdateOptions<MongoMigrationEntity> { IsUpsert = true };
public MongoMigrationStatus(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoMigrationStatus(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }

15
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbEngine.cs

@ -1,15 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.MongoDb
{
public enum MongoDbEngine
{
DocumentDb,
MongoDb,
}
}

24
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs

@ -1,24 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.MongoDb
{
public sealed class MongoDbOptions
{
public MongoDbEngine Engine { get; set; } = MongoDbEngine.MongoDb;
public bool IsDocumentDb
{
get { return Engine == MongoDbEngine.DocumentDb; }
}
public bool IsMongoDb
{
get { return Engine == MongoDbEngine.MongoDb; }
}
}
}

16
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs

@ -31,7 +31,6 @@ namespace Squidex.Infrastructure.MongoDb
protected static readonly ProjectionDefinitionBuilder<TEntity> Projection = Builders<TEntity>.Projection; protected static readonly ProjectionDefinitionBuilder<TEntity> Projection = Builders<TEntity>.Projection;
private readonly IMongoDatabase mongoDatabase; private readonly IMongoDatabase mongoDatabase;
private readonly MongoDbOptions options;
private Lazy<IMongoCollection<TEntity>> mongoCollection; private Lazy<IMongoCollection<TEntity>> mongoCollection;
protected IMongoCollection<TEntity> Collection protected IMongoCollection<TEntity> Collection
@ -44,11 +43,6 @@ namespace Squidex.Infrastructure.MongoDb
get { return mongoDatabase; } get { return mongoDatabase; }
} }
protected MongoDbOptions Options
{
get { return options; }
}
static MongoRepositoryBase() static MongoRepositoryBase()
{ {
RefTokenSerializer.Register(); RefTokenSerializer.Register();
@ -56,15 +50,12 @@ namespace Squidex.Infrastructure.MongoDb
InstantSerializer.Register(); InstantSerializer.Register();
} }
protected MongoRepositoryBase(IMongoDatabase database, IOptions<MongoDbOptions> options) protected MongoRepositoryBase(IMongoDatabase database)
{ {
Guard.NotNull(database, nameof(database)); Guard.NotNull(database, nameof(database));
Guard.NotNull(options, nameof(options));
mongoDatabase = database; mongoDatabase = database;
mongoCollection = CreateCollection(); mongoCollection = CreateCollection();
this.options = options.Value;
} }
protected virtual MongoCollectionSettings CollectionSettings() protected virtual MongoCollectionSettings CollectionSettings()
@ -72,11 +63,6 @@ namespace Squidex.Infrastructure.MongoDb
return new MongoCollectionSettings(); return new MongoCollectionSettings();
} }
protected virtual string ShardKey()
{
return "_id";
}
protected virtual string CollectionName() protected virtual string CollectionName()
{ {
return string.Format(CultureInfo.InvariantCulture, CollectionFormat, typeof(TEntity).Name); return string.Format(CultureInfo.InvariantCulture, CollectionFormat, typeof(TEntity).Name);

4
src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs

@ -20,8 +20,8 @@ namespace Squidex.Infrastructure.States
{ {
public class MongoSnapshotStore<T, TKey> : MongoRepositoryBase<MongoState<T, TKey>>, ISnapshotStore<T, TKey> public class MongoSnapshotStore<T, TKey> : MongoRepositoryBase<MongoState<T, TKey>>, ISnapshotStore<T, TKey>
{ {
public MongoSnapshotStore(IMongoDatabase database, IOptions<MongoDbOptions> options, JsonSerializer jsonSerializer) public MongoSnapshotStore(IMongoDatabase database, JsonSerializer jsonSerializer)
: base(database, options) : base(database)
{ {
Guard.NotNull(jsonSerializer, nameof(jsonSerializer)); Guard.NotNull(jsonSerializer, nameof(jsonSerializer));

4
src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs

@ -20,8 +20,8 @@ namespace Squidex.Infrastructure.UsageTracking
{ {
private static readonly BulkWriteOptions Unordered = new BulkWriteOptions { IsOrdered = false }; private static readonly BulkWriteOptions Unordered = new BulkWriteOptions { IsOrdered = false };
public MongoUsageRepository(IMongoDatabase database, IOptions<MongoDbOptions> options) public MongoUsageRepository(IMongoDatabase database)
: base(database, options) : base(database)
{ {
} }

2
src/Squidex/Config/Domain/EventStoreServices.cs

@ -40,7 +40,7 @@ namespace Squidex.Config.Domain
var mongoClient = Singletons<IMongoClient>.GetOrAdd(mongoConfiguration, s => new MongoClient(s)); var mongoClient = Singletons<IMongoClient>.GetOrAdd(mongoConfiguration, s => new MongoClient(s));
var mongDatabase = mongoClient.GetDatabase(mongoDatabaseName); var mongDatabase = mongoClient.GetDatabase(mongoDatabaseName);
return new MongoEventStore(mongDatabase, c.GetRequiredService<IOptions<MongoDbOptions>>(), c.GetRequiredService<IEventNotifier>()); return new MongoEventStore(mongDatabase, c.GetRequiredService<IEventNotifier>());
}) })
.As<IEventStore>(); .As<IEventStore>();
}, },

3
src/Squidex/Config/Domain/StoreServices.cs

@ -52,8 +52,6 @@ namespace Squidex.Config.Domain
var mongoDatabaseName = config.GetRequiredValue("store:mongoDb:database"); var mongoDatabaseName = config.GetRequiredValue("store:mongoDb:database");
var mongoContentDatabaseName = config.GetOptionalValue("store:mongoDb:contentDatabase", mongoDatabaseName); var mongoContentDatabaseName = config.GetOptionalValue("store:mongoDb:contentDatabase", mongoDatabaseName);
services.Configure<MongoDbOptions>(config.GetSection("store:mongoDB"));
services.AddSingleton(typeof(ISnapshotStore<,>), typeof(MongoSnapshotStore<,>)); services.AddSingleton(typeof(ISnapshotStore<,>), typeof(MongoSnapshotStore<,>));
services.AddSingletonAs(_ => Singletons<IMongoClient>.GetOrAdd(mongoConfiguration, s => new MongoClient(s))) services.AddSingletonAs(_ => Singletons<IMongoClient>.GetOrAdd(mongoConfiguration, s => new MongoClient(s)))
@ -105,7 +103,6 @@ namespace Squidex.Config.Domain
services.AddSingletonAs(c => new MongoContentRepository( services.AddSingletonAs(c => new MongoContentRepository(
c.GetRequiredService<IMongoClient>().GetDatabase(mongoContentDatabaseName), c.GetRequiredService<IMongoClient>().GetDatabase(mongoContentDatabaseName),
c.GetRequiredService<IOptions<MongoDbOptions>>(),
c.GetRequiredService<IAppProvider>(), c.GetRequiredService<IAppProvider>(),
c.GetRequiredService<IJsonSerializer>(), c.GetRequiredService<IJsonSerializer>(),
c.GetRequiredService<ITextIndexer>(), c.GetRequiredService<ITextIndexer>(),

6
src/Squidex/appsettings.json

@ -395,11 +395,7 @@
/* /*
* The database for all your other read collections. * The database for all your other read collections.
*/ */
"database": "Squidex", "database": "Squidex"
/*
* The MongoDb Engine. Supported: MongoDb, DocumentDb
*/
"engine": "MongoDb"
} }
}, },

2
tests/Squidex.Infrastructure.Tests/EventSourcing/MongoEventStoreFixture.cs

@ -29,7 +29,7 @@ namespace Squidex.Infrastructure.EventSourcing
BsonJsonConvention.Register(JsonSerializer.Create(JsonHelper.DefaultSettings())); BsonJsonConvention.Register(JsonSerializer.Create(JsonHelper.DefaultSettings()));
EventStore = new MongoEventStore(mongoDatabase, Options.Create(new MongoDbOptions()), notifier); EventStore = new MongoEventStore(mongoDatabase, notifier);
EventStore.InitializeAsync().Wait(); EventStore.InitializeAsync().Wait();
} }

Loading…
Cancel
Save