|
|
@ -9,6 +9,8 @@ using System; |
|
|
using System.Globalization; |
|
|
using System.Globalization; |
|
|
using System.Threading; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
|
|
using MongoDB.Bson; |
|
|
using MongoDB.Driver; |
|
|
using MongoDB.Driver; |
|
|
using Squidex.Infrastructure.Tasks; |
|
|
using Squidex.Infrastructure.Tasks; |
|
|
|
|
|
|
|
|
@ -29,6 +31,7 @@ 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 |
|
|
@ -41,6 +44,11 @@ namespace Squidex.Infrastructure.MongoDb |
|
|
get { return mongoDatabase; } |
|
|
get { return mongoDatabase; } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected MongoDbOptions Options |
|
|
|
|
|
{ |
|
|
|
|
|
get { return options; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static MongoRepositoryBase() |
|
|
static MongoRepositoryBase() |
|
|
{ |
|
|
{ |
|
|
RefTokenSerializer.Register(); |
|
|
RefTokenSerializer.Register(); |
|
|
@ -48,12 +56,15 @@ namespace Squidex.Infrastructure.MongoDb |
|
|
InstantSerializer.Register(); |
|
|
InstantSerializer.Register(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected MongoRepositoryBase(IMongoDatabase database) |
|
|
protected MongoRepositoryBase(IMongoDatabase database, IOptions<MongoDbOptions> options) |
|
|
{ |
|
|
{ |
|
|
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() |
|
|
@ -61,6 +72,11 @@ 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); |
|
|
|