Browse Source

Enable nullable annotations for Volo.Abp.MongoDb

pull/17549/head
liangshiwei 3 years ago
parent
commit
fd55eb68f2
  1. 2
      framework/src/Volo.Abp.MongoDB/Microsoft/Extensions/DependencyInjection/AbpMongoDbServiceCollectionExtensions.cs
  2. 2
      framework/src/Volo.Abp.MongoDB/Volo.Abp.MongoDB.csproj
  3. 6
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbBulkOperationProvider.cs
  4. 4
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs
  5. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepositoryFilterer.cs
  6. 32
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  7. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepositoryFilterer.cs
  8. 4
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs
  9. 12
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbContext.cs
  10. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbContextOptions.cs
  11. 3
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoModelBuilderConfigurationOptions.cs
  12. 6
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/IncomingEventRecord.cs
  13. 4
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/OutgoingEventRecord.cs
  14. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IAbpMongoDbContext.cs
  15. 4
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoModelBuilder.cs
  16. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoCollectionAttribute.cs
  17. 24
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs
  18. 2
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoEntityModelBuilder.cs
  19. 6
      framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs
  20. 8
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Uow/MongoDB/UnitOfWorkMongoDbContextProvider.cs

2
framework/src/Volo.Abp.MongoDB/Microsoft/Extensions/DependencyInjection/AbpMongoDbServiceCollectionExtensions.cs

@ -10,7 +10,7 @@ namespace Microsoft.Extensions.DependencyInjection;
public static class AbpMongoDbServiceCollectionExtensions public static class AbpMongoDbServiceCollectionExtensions
{ {
public static IServiceCollection AddMongoDbContext<TMongoDbContext>(this IServiceCollection services, Action<IAbpMongoDbContextRegistrationOptionsBuilder> optionsBuilder = null) //Created overload instead of default parameter public static IServiceCollection AddMongoDbContext<TMongoDbContext>(this IServiceCollection services, Action<IAbpMongoDbContextRegistrationOptionsBuilder>? optionsBuilder = null) //Created overload instead of default parameter
where TMongoDbContext : AbpMongoDbContext where TMongoDbContext : AbpMongoDbContext
{ {
var options = new AbpMongoDbContextRegistrationOptions(typeof(TMongoDbContext), services); var options = new AbpMongoDbContextRegistrationOptions(typeof(TMongoDbContext), services);

2
framework/src/Volo.Abp.MongoDB/Volo.Abp.MongoDB.csproj

@ -5,6 +5,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks> <TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.MongoDB</AssemblyName> <AssemblyName>Volo.Abp.MongoDB</AssemblyName>
<PackageId>Volo.Abp.MongoDB</PackageId> <PackageId>Volo.Abp.MongoDB</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

6
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbBulkOperationProvider.cs

@ -11,7 +11,7 @@ public interface IMongoDbBulkOperationProvider
Task InsertManyAsync<TEntity>( Task InsertManyAsync<TEntity>(
IMongoDbRepository<TEntity> repository, IMongoDbRepository<TEntity> repository,
IEnumerable<TEntity> entities, IEnumerable<TEntity> entities,
IClientSessionHandle sessionHandle, IClientSessionHandle? sessionHandle,
bool autoSave, bool autoSave,
CancellationToken cancellationToken CancellationToken cancellationToken
) )
@ -20,7 +20,7 @@ public interface IMongoDbBulkOperationProvider
Task UpdateManyAsync<TEntity>( Task UpdateManyAsync<TEntity>(
IMongoDbRepository<TEntity> repository, IMongoDbRepository<TEntity> repository,
IEnumerable<TEntity> entities, IEnumerable<TEntity> entities,
IClientSessionHandle sessionHandle, IClientSessionHandle? sessionHandle,
bool autoSave, bool autoSave,
CancellationToken cancellationToken CancellationToken cancellationToken
) )
@ -29,7 +29,7 @@ public interface IMongoDbBulkOperationProvider
Task DeleteManyAsync<TEntity>( Task DeleteManyAsync<TEntity>(
IMongoDbRepository<TEntity> repository, IMongoDbRepository<TEntity> repository,
IEnumerable<TEntity> entities, IEnumerable<TEntity> entities,
IClientSessionHandle sessionHandle, IClientSessionHandle? sessionHandle,
bool autoSave, bool autoSave,
CancellationToken cancellationToken CancellationToken cancellationToken
) )

4
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepository.cs

@ -23,9 +23,9 @@ public interface IMongoDbRepository<TEntity> : IRepository<TEntity>
[Obsolete("Use GetMongoQueryableAsync method.")] [Obsolete("Use GetMongoQueryableAsync method.")]
IMongoQueryable<TEntity> GetMongoQueryable(); IMongoQueryable<TEntity> GetMongoQueryable();
Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions options = null); Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null);
Task<IAggregateFluent<TEntity>> GetAggregateAsync(CancellationToken cancellationToken = default, AggregateOptions options = null); Task<IAggregateFluent<TEntity>> GetAggregateAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null);
} }
public interface IMongoDbRepository<TEntity, TKey> : IMongoDbRepository<TEntity>, IRepository<TEntity, TKey> public interface IMongoDbRepository<TEntity, TKey> : IMongoDbRepository<TEntity>, IRepository<TEntity, TKey>

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/IMongoDbRepositoryFilterer.cs

@ -17,7 +17,7 @@ public interface IMongoDbRepositoryFilterer<TEntity, TKey> : IMongoDbRepositoryF
{ {
Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TKey id, bool applyFilters = false); Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TKey id, bool applyFilters = false);
Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string concurrencyStamp = null); Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string? concurrencyStamp = null);
/// <summary> /// <summary>
/// Creates filter for given entities. /// Creates filter for given entities.

32
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -43,9 +43,9 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
} }
[Obsolete("Use GetSessionHandleAsync method.")] [Obsolete("Use GetSessionHandleAsync method.")]
protected virtual IClientSessionHandle SessionHandle => DbContext.SessionHandle; protected virtual IClientSessionHandle? SessionHandle => DbContext.SessionHandle;
protected async Task<IClientSessionHandle> GetSessionHandleAsync(CancellationToken cancellationToken = default) protected async Task<IClientSessionHandle?> GetSessionHandleAsync(CancellationToken cancellationToken = default)
{ {
return (await GetDbContextAsync(GetCancellationToken(cancellationToken))).SessionHandle; return (await GetDbContextAsync(GetCancellationToken(cancellationToken))).SessionHandle;
} }
@ -96,9 +96,9 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
public IAuditPropertySetter AuditPropertySetter => LazyServiceProvider.LazyGetRequiredService<IAuditPropertySetter>(); public IAuditPropertySetter AuditPropertySetter => LazyServiceProvider.LazyGetRequiredService<IAuditPropertySetter>();
public IMongoDbBulkOperationProvider BulkOperationProvider => LazyServiceProvider.LazyGetService<IMongoDbBulkOperationProvider>(); public IMongoDbBulkOperationProvider? BulkOperationProvider => LazyServiceProvider.LazyGetService<IMongoDbBulkOperationProvider>();
public IMongoDbRepositoryFilterer<TEntity> RepositoryFilterer => LazyServiceProvider.LazyGetService<IMongoDbRepositoryFilterer<TEntity>>(); public IMongoDbRepositoryFilterer<TEntity> RepositoryFilterer => LazyServiceProvider.LazyGetService<IMongoDbRepositoryFilterer<TEntity>>()!;
public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider) public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider)
{ {
@ -382,7 +382,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity)) if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity))
{ {
ObjectHelper.TrySetProperty(((ISoftDelete)entity), x => x.IsDeleted, () => true); ObjectHelper.TrySetProperty(((ISoftDelete)entity), x => x.IsDeleted, () => true);
softDeletedEntities.Add(entity, SetNewConcurrencyStamp(entity)); softDeletedEntities.Add(entity, SetNewConcurrencyStamp(entity)!);
} }
else else
{ {
@ -525,7 +525,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
return await GetMongoQueryableAsync(); return await GetMongoQueryableAsync();
} }
public async override Task<TEntity> FindAsync( public async override Task<TEntity?> FindAsync(
Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, bool>> predicate,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -547,12 +547,12 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
); );
} }
public virtual Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions aggregateOptions = null) public virtual Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
{ {
return GetMongoQueryableAsync<TEntity>(cancellationToken, aggregateOptions); return GetMongoQueryableAsync<TEntity>(cancellationToken, aggregateOptions);
} }
protected virtual async Task<IMongoQueryable<TOtherEntity>> GetMongoQueryableAsync<TOtherEntity>(CancellationToken cancellationToken = default, AggregateOptions aggregateOptions = null) protected virtual async Task<IMongoQueryable<TOtherEntity>> GetMongoQueryableAsync<TOtherEntity>(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
@ -566,7 +566,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
); );
} }
public virtual async Task<IAggregateFluent<TEntity>> GetAggregateAsync(CancellationToken cancellationToken = default, AggregateOptions aggregateOptions = null) public virtual async Task<IAggregateFluent<TEntity>> GetAggregateAsync(CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
@ -602,7 +602,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
return hardDeletedEntities.Contains(entity); return hardDeletedEntities.Contains(entity);
} }
protected virtual Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string concurrencyStamp = null) protected virtual Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string? concurrencyStamp = null)
{ {
throw new NotImplementedException( throw new NotImplementedException(
$"{nameof(CreateEntityFilterAsync)} is not implemented for MongoDB by default. It should be overriden and implemented by the deriving class!" $"{nameof(CreateEntityFilterAsync)} is not implemented for MongoDB by default. It should be overriden and implemented by the deriving class!"
@ -737,7 +737,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
/// if given entity implements <see cref="IHasConcurrencyStamp"/> interface. /// if given entity implements <see cref="IHasConcurrencyStamp"/> interface.
/// Returns the old <see cref="IHasConcurrencyStamp.ConcurrencyStamp"/> value. /// Returns the old <see cref="IHasConcurrencyStamp.ConcurrencyStamp"/> value.
/// </summary> /// </summary>
protected virtual string SetNewConcurrencyStamp(TEntity entity) protected virtual string? SetNewConcurrencyStamp(TEntity entity)
{ {
if (!(entity is IHasConcurrencyStamp concurrencyStampEntity)) if (!(entity is IHasConcurrencyStamp concurrencyStampEntity))
{ {
@ -770,7 +770,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity, TKey>
where TMongoDbContext : IAbpMongoDbContext where TMongoDbContext : IAbpMongoDbContext
where TEntity : class, IEntity<TKey> where TEntity : class, IEntity<TKey>
{ {
public IMongoDbRepositoryFilterer<TEntity, TKey> RepositoryFiltererWithKey => LazyServiceProvider.LazyGetService<IMongoDbRepositoryFilterer<TEntity, TKey>>(); public IMongoDbRepositoryFilterer<TEntity, TKey> RepositoryFiltererWithKey => LazyServiceProvider.LazyGetService<IMongoDbRepositoryFilterer<TEntity, TKey>>()!;
public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider) public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
@ -793,14 +793,14 @@ public class MongoDbRepository<TMongoDbContext, TEntity, TKey>
return entity; return entity;
} }
public virtual async Task<TEntity> FindAsync( public virtual async Task<TEntity?> FindAsync(
TKey id, TKey id,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await ApplyDataFilters(await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Id.Equals(id)).FirstOrDefaultAsync(cancellationToken); return await ApplyDataFilters(await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Id!.Equals(id)).FirstOrDefaultAsync(cancellationToken);
} }
public virtual Task DeleteAsync( public virtual Task DeleteAsync(
@ -808,7 +808,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity, TKey>
bool autoSave = false, bool autoSave = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return DeleteAsync(x => x.Id.Equals(id), autoSave, cancellationToken); return DeleteAsync(x => x.Id!.Equals(id), autoSave, cancellationToken);
} }
public virtual async Task DeleteManyAsync([NotNull] IEnumerable<TKey> ids, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteManyAsync([NotNull] IEnumerable<TKey> ids, bool autoSave = false, CancellationToken cancellationToken = default)
@ -832,7 +832,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity, TKey>
return base.ApplyDataFilters<TQueryable, TOtherEntity>(query); return base.ApplyDataFilters<TQueryable, TOtherEntity>(query);
} }
protected async override Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string concurrencyStamp = null) protected async override Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string? concurrencyStamp = null)
{ {
return await RepositoryFiltererWithKey.CreateEntityFilterAsync(entity, withConcurrencyStamp, concurrencyStamp); return await RepositoryFiltererWithKey.CreateEntityFilterAsync(entity, withConcurrencyStamp, concurrencyStamp);
} }

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepositoryFilterer.cs

@ -67,7 +67,7 @@ public class MongoDbRepositoryFilterer<TEntity, TKey> : MongoDbRepositoryFiltere
return Builders<TEntity>.Filter.And(filters); return Builders<TEntity>.Filter.And(filters);
} }
public virtual Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string concurrencyStamp = null) public virtual Task<FilterDefinition<TEntity>> CreateEntityFilterAsync(TEntity entity, bool withConcurrencyStamp = false, string? concurrencyStamp = null)
{ {
if (!withConcurrencyStamp || !(entity is IHasConcurrencyStamp entityWithConcurrencyStamp)) if (!withConcurrencyStamp || !(entity is IHasConcurrencyStamp entityWithConcurrencyStamp))
{ {

4
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs

@ -43,13 +43,13 @@ public static class MongoDbCoreRepositoryExtensions
return repository.ToMongoDbRepository().GetMongoQueryable(); return repository.ToMongoDbRepository().GetMongoQueryable();
} }
public static Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions aggregateOptions = null) public static Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
return repository.ToMongoDbRepository().GetMongoQueryableAsync(cancellationToken, aggregateOptions); return repository.ToMongoDbRepository().GetMongoQueryableAsync(cancellationToken, aggregateOptions);
} }
public static Task<IAggregateFluent<TEntity>> GetAggregateAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions aggregateOptions = null) public static Task<IAggregateFluent<TEntity>> GetAggregateAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
return repository.ToMongoDbRepository().GetAggregateAsync(cancellationToken, aggregateOptions); return repository.ToMongoDbRepository().GetAggregateAsync(cancellationToken, aggregateOptions);

12
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbContext.cs

@ -6,22 +6,22 @@ namespace Volo.Abp.MongoDB;
public abstract class AbpMongoDbContext : IAbpMongoDbContext, ITransientDependency public abstract class AbpMongoDbContext : IAbpMongoDbContext, ITransientDependency
{ {
public IAbpLazyServiceProvider LazyServiceProvider { get; set; } public IAbpLazyServiceProvider LazyServiceProvider { get; set; } = default!;
public IMongoModelSource ModelSource { get; set; } public IMongoModelSource ModelSource { get; set; } = default!;
public IMongoClient Client { get; private set; } public IMongoClient Client { get; private set; } = default!;
public IMongoDatabase Database { get; private set; } public IMongoDatabase Database { get; private set; } = default!;
public IClientSessionHandle SessionHandle { get; private set; } public IClientSessionHandle? SessionHandle { get; private set; }
protected internal virtual void CreateModel(IMongoModelBuilder modelBuilder) protected internal virtual void CreateModel(IMongoModelBuilder modelBuilder)
{ {
} }
public virtual void InitializeDatabase(IMongoDatabase database, IMongoClient client, IClientSessionHandle sessionHandle) public virtual void InitializeDatabase(IMongoDatabase database, IMongoClient client, IClientSessionHandle? sessionHandle)
{ {
Database = database; Database = database;
Client = client; Client = client;

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbContextOptions.cs

@ -12,7 +12,7 @@ public class AbpMongoDbContextOptions
{ {
internal Dictionary<MultiTenantDbContextType, Type> DbContextReplacements { get; } internal Dictionary<MultiTenantDbContextType, Type> DbContextReplacements { get; }
public Action<MongoClientSettings> MongoClientSettingsConfigurer { get; set; } public Action<MongoClientSettings>? MongoClientSettingsConfigurer { get; set; }
public AbpMongoDbContextOptions() public AbpMongoDbContextOptions()
{ {

3
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoModelBuilderConfigurationOptions.cs

@ -12,7 +12,8 @@ public class AbpMongoModelBuilderConfigurationOptions
_collectionPrefix = value; _collectionPrefix = value;
} }
} }
private string _collectionPrefix;
private string _collectionPrefix = default!;
public AbpMongoModelBuilderConfigurationOptions([NotNull] string collectionPrefix = "") public AbpMongoModelBuilderConfigurationOptions([NotNull] string collectionPrefix = "")
{ {

6
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/IncomingEventRecord.cs

@ -15,11 +15,11 @@ public class IncomingEventRecord :
public ExtraPropertyDictionary ExtraProperties { get; private set; } public ExtraPropertyDictionary ExtraProperties { get; private set; }
public string MessageId { get; private set; } public string MessageId { get; private set; } = default!;
public string EventName { get; private set; } public string EventName { get; private set; } = default!;
public byte[] EventData { get; private set; } public byte[] EventData { get; private set; } = default!;
public DateTime CreationTime { get; private set; } public DateTime CreationTime { get; private set; }

4
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/DistributedEvents/OutgoingEventRecord.cs

@ -15,9 +15,9 @@ public class OutgoingEventRecord :
public ExtraPropertyDictionary ExtraProperties { get; private set; } public ExtraPropertyDictionary ExtraProperties { get; private set; }
public string EventName { get; private set; } public string EventName { get; private set; } = default!;
public byte[] EventData { get; private set; } public byte[] EventData { get; private set; } = default!;
public DateTime CreationTime { get; private set; } public DateTime CreationTime { get; private set; }

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IAbpMongoDbContext.cs

@ -10,5 +10,5 @@ public interface IAbpMongoDbContext
IMongoCollection<T> Collection<T>(); IMongoCollection<T> Collection<T>();
IClientSessionHandle SessionHandle { get; } IClientSessionHandle? SessionHandle { get; }
} }

4
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoModelBuilder.cs

@ -6,9 +6,9 @@ namespace Volo.Abp.MongoDB;
public interface IMongoModelBuilder public interface IMongoModelBuilder
{ {
void Entity<TEntity>(Action<IMongoEntityModelBuilder<TEntity>> buildAction = null); void Entity<TEntity>(Action<IMongoEntityModelBuilder<TEntity>>? buildAction = null);
void Entity([NotNull] Type entityType, Action<IMongoEntityModelBuilder> buildAction = null); void Entity([NotNull] Type entityType, Action<IMongoEntityModelBuilder>? buildAction = null);
IReadOnlyList<IMongoEntityModel> GetEntities(); IReadOnlyList<IMongoEntityModel> GetEntities();
} }

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoCollectionAttribute.cs

@ -4,7 +4,7 @@ namespace Volo.Abp.MongoDB;
public class MongoCollectionAttribute : Attribute public class MongoCollectionAttribute : Attribute
{ {
public string CollectionName { get; set; } public string? CollectionName { get; set; }
public MongoCollectionAttribute() public MongoCollectionAttribute()
{ {

24
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoDbAsyncQueryableProvider.cs

@ -74,15 +74,15 @@ public class MongoDbAsyncQueryableProvider : IAsyncQueryableProvider, ISingleton
return GetMongoQueryable(queryable).FirstAsync(predicate, cancellationToken); return GetMongoQueryable(queryable).FirstAsync(predicate, cancellationToken);
} }
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T?> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).FirstOrDefaultAsync(cancellationToken); return GetMongoQueryable(queryable).FirstOrDefaultAsync(cancellationToken)!;
} }
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, public Task<T?> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).FirstOrDefaultAsync(predicate, cancellationToken); return GetMongoQueryable(queryable).FirstOrDefaultAsync(predicate, cancellationToken)!;
} }
public Task<T> LastAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> LastAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
@ -95,15 +95,15 @@ public class MongoDbAsyncQueryableProvider : IAsyncQueryableProvider, ISingleton
return Task.FromResult(GetMongoQueryable(queryable).Last(predicate)); return Task.FromResult(GetMongoQueryable(queryable).Last(predicate));
} }
public Task<T> LastOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T?> LastOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return Task.FromResult(GetMongoQueryable(queryable).LastOrDefault()); return Task.FromResult<T?>(GetMongoQueryable(queryable).LastOrDefault());
} }
public Task<T> LastOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, public Task<T?> LastOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return Task.FromResult(GetMongoQueryable(queryable).LastOrDefault(predicate)); return Task.FromResult<T?>(GetMongoQueryable(queryable).LastOrDefault(predicate));
} }
public Task<T> SingleAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> SingleAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
@ -116,15 +116,15 @@ public class MongoDbAsyncQueryableProvider : IAsyncQueryableProvider, ISingleton
return GetMongoQueryable(queryable).SingleAsync(predicate, cancellationToken); return GetMongoQueryable(queryable).SingleAsync(predicate, cancellationToken);
} }
public Task<T> SingleOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T?> SingleOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SingleOrDefaultAsync(cancellationToken); return GetMongoQueryable(queryable).SingleOrDefaultAsync(cancellationToken)!;
} }
public Task<T> SingleOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, public Task<T?> SingleOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return GetMongoQueryable(queryable).SingleOrDefaultAsync(predicate, cancellationToken); return GetMongoQueryable(queryable).SingleOrDefaultAsync(predicate, cancellationToken)!;
} }
public Task<T> MinAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default) public Task<T> MinAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)

2
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoEntityModelBuilder.cs

@ -11,7 +11,7 @@ public class MongoEntityModelBuilder<TEntity> :
{ {
public Type EntityType { get; } public Type EntityType { get; }
public string CollectionName { get; set; } public string CollectionName { get; set; } = default!;
BsonClassMap IMongoEntityModelBuilder.BsonMap => _bsonClassMap; BsonClassMap IMongoEntityModelBuilder.BsonMap => _bsonClassMap;
BsonClassMap<TEntity> IMongoEntityModelBuilder<TEntity>.BsonMap => _bsonClassMap; BsonClassMap<TEntity> IMongoEntityModelBuilder<TEntity>.BsonMap => _bsonClassMap;

6
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs

@ -121,7 +121,7 @@ public class MongoModelBuilder : IMongoModelBuilder
return dbContext.LazyServiceProvider.LazyGetRequiredService<IOptions<AbpClockOptions>>().Value.Kind; return dbContext.LazyServiceProvider.LazyGetRequiredService<IOptions<AbpClockOptions>>().Value.Kind;
} }
public virtual void Entity<TEntity>(Action<IMongoEntityModelBuilder<TEntity>> buildAction = null) public virtual void Entity<TEntity>(Action<IMongoEntityModelBuilder<TEntity>>? buildAction = null)
{ {
var model = (IMongoEntityModelBuilder<TEntity>)_entityModelBuilders.GetOrAdd( var model = (IMongoEntityModelBuilder<TEntity>)_entityModelBuilders.GetOrAdd(
typeof(TEntity), typeof(TEntity),
@ -131,7 +131,7 @@ public class MongoModelBuilder : IMongoModelBuilder
buildAction?.Invoke(model); buildAction?.Invoke(model);
} }
public virtual void Entity(Type entityType, Action<IMongoEntityModelBuilder> buildAction = null) public virtual void Entity(Type entityType, Action<IMongoEntityModelBuilder>? buildAction = null)
{ {
Check.NotNull(entityType, nameof(entityType)); Check.NotNull(entityType, nameof(entityType));
@ -139,7 +139,7 @@ public class MongoModelBuilder : IMongoModelBuilder
entityType, entityType,
() => (IMongoEntityModelBuilder)Activator.CreateInstance( () => (IMongoEntityModelBuilder)Activator.CreateInstance(
typeof(MongoEntityModelBuilder<>).MakeGenericType(entityType) typeof(MongoEntityModelBuilder<>).MakeGenericType(entityType)
) )!
); );
buildAction?.Invoke(model); buildAction?.Invoke(model);

8
framework/src/Volo.Abp.MongoDB/Volo/Abp/Uow/MongoDB/UnitOfWorkMongoDbContextProvider.cs

@ -131,7 +131,7 @@ public class UnitOfWorkMongoDbContextProvider<TMongoDbContext> : IMongoDbContext
var client = CreateMongoClient(mongoUrl); var client = CreateMongoClient(mongoUrl);
var database = client.GetDatabase(databaseName); var database = client.GetDatabase(databaseName);
if (unitOfWork.Options.IsTransactional) if (unitOfWork.Options!.IsTransactional)
{ {
return CreateDbContextWithTransaction(unitOfWork, mongoUrl, client, database); return CreateDbContextWithTransaction(unitOfWork, mongoUrl, client, database);
} }
@ -151,7 +151,7 @@ public class UnitOfWorkMongoDbContextProvider<TMongoDbContext> : IMongoDbContext
var client = CreateMongoClient(mongoUrl); var client = CreateMongoClient(mongoUrl);
var database = client.GetDatabase(databaseName); var database = client.GetDatabase(databaseName);
if (unitOfWork.Options.IsTransactional) if (unitOfWork.Options!.IsTransactional)
{ {
return await CreateDbContextWithTransactionAsync( return await CreateDbContextWithTransactionAsync(
unitOfWork, unitOfWork,
@ -183,7 +183,7 @@ public class UnitOfWorkMongoDbContextProvider<TMongoDbContext> : IMongoDbContext
{ {
var session = client.StartSession(); var session = client.StartSession();
if (unitOfWork.Options.Timeout.HasValue) if (unitOfWork.Options!.Timeout.HasValue)
{ {
session.AdvanceOperationTime(new BsonTimestamp(unitOfWork.Options.Timeout.Value)); session.AdvanceOperationTime(new BsonTimestamp(unitOfWork.Options.Timeout.Value));
} }
@ -233,7 +233,7 @@ public class UnitOfWorkMongoDbContextProvider<TMongoDbContext> : IMongoDbContext
{ {
var session = await client.StartSessionAsync(cancellationToken: GetCancellationToken(cancellationToken)); var session = await client.StartSessionAsync(cancellationToken: GetCancellationToken(cancellationToken));
if (unitOfWork.Options.Timeout.HasValue) if (unitOfWork.Options!.Timeout.HasValue)
{ {
session.AdvanceOperationTime(new BsonTimestamp(unitOfWork.Options.Timeout.Value)); session.AdvanceOperationTime(new BsonTimestamp(unitOfWork.Options.Timeout.Value));
} }

Loading…
Cancel
Save