Browse Source

Enable #nullable for mongo storage.

master
Savorboard 3 years ago
parent
commit
b36fb6562d
6 changed files with 20 additions and 25 deletions
  1. +1
    -1
      src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs
  2. +1
    -1
      src/DotNetCore.CAP.MongoDB/CAP.MongoDBOptions.cs
  3. +2
    -7
      src/DotNetCore.CAP.MongoDB/DotNetCore.CAP.MongoDB.csproj
  4. +4
    -4
      src/DotNetCore.CAP.MongoDB/IClientSessionHandle.CAP.cs
  5. +3
    -3
      src/DotNetCore.CAP.MongoDB/IDataStorage.MongoDB.cs
  6. +9
    -9
      src/DotNetCore.CAP.MongoDB/StorageMessage.cs

+ 1
- 1
src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs View File

@@ -32,7 +32,7 @@ namespace DotNetCore.CAP.MongoDB
//Try to add IMongoClient if does not exists
services.TryAddSingleton<IMongoClient>(x =>
{
var options = x.GetService<IOptions<MongoDBOptions>>().Value;
var options = x.GetRequiredService<IOptions<MongoDBOptions>>().Value;
return new MongoClient(options.DatabaseConnection);
});
}


+ 1
- 1
src/DotNetCore.CAP.MongoDB/CAP.MongoDBOptions.cs View File

@@ -30,6 +30,6 @@ namespace DotNetCore.CAP.MongoDB
/// </summary>
public string PublishedCollection { get; set; } = "cap.published";

internal string Version { get; set; }
internal string Version { get; set; } = default!;
}
}

+ 2
- 7
src/DotNetCore.CAP.MongoDB/DotNetCore.CAP.MongoDB.csproj View File

@@ -2,15 +2,10 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>DotNetCore.CAP.MongoDB</AssemblyName>
<Nullable>enable</Nullable>
<PackageTags>$(PackageTags);MongoDB</PackageTags>
</PropertyGroup>
<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\netstandard2.1\DotNetCore.CAP.MongoDB.xml</DocumentationFile>
<NoWarn>1701;1702;1705;CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\DotNetCore.CAP\DotNetCore.CAP.csproj" />
</ItemGroup>


+ 4
- 4
src/DotNetCore.CAP.MongoDB/IClientSessionHandle.CAP.cs View File

@@ -19,7 +19,7 @@ namespace MongoDB.Driver
public CapMongoDbClientSessionHandle(ICapTransaction transaction)
{
_transaction = transaction;
_sessionHandle = (IClientSessionHandle)_transaction.DbTransaction;
_sessionHandle = (IClientSessionHandle)_transaction.DbTransaction!;
}

public void Dispose()
@@ -59,7 +59,7 @@ namespace MongoDB.Driver
return Task.CompletedTask;
}

public void StartTransaction(TransactionOptions transactionOptions = null)
public void StartTransaction(TransactionOptions? transactionOptions = null)
{
_sessionHandle.StartTransaction(transactionOptions);
}
@@ -78,12 +78,12 @@ namespace MongoDB.Driver
return _sessionHandle.Fork();
}

public TResult WithTransaction<TResult>(Func<IClientSessionHandle, CancellationToken, TResult> callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default)
public TResult WithTransaction<TResult>(Func<IClientSessionHandle, CancellationToken, TResult> callback, TransactionOptions? transactionOptions = null, CancellationToken cancellationToken = default)
{
return _sessionHandle.WithTransaction(callback, transactionOptions, cancellationToken);
}

public Task<TResult> WithTransactionAsync<TResult>(Func<IClientSessionHandle, CancellationToken, Task<TResult>> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default)
public Task<TResult> WithTransactionAsync<TResult>(Func<IClientSessionHandle, CancellationToken, Task<TResult>> callbackAsync, TransactionOptions? transactionOptions = null, CancellationToken cancellationToken = default)
{
return _sessionHandle.WithTransactionAsync(callbackAsync, transactionOptions, cancellationToken);
}


+ 3
- 3
src/DotNetCore.CAP.MongoDB/IDataStorage.MongoDB.cs View File

@@ -63,7 +63,7 @@ namespace DotNetCore.CAP.MongoDB
await collection.UpdateOneAsync(x => x.Id == long.Parse(message.DbId), updateDef);
}

public MediumMessage StoreMessage(string name, Message content, object dbTransaction = null)
public MediumMessage StoreMessage(string name, Message content, object? dbTransaction = null)
{
var insertOptions = new InsertOneOptions { BypassDocumentValidation = false };

@@ -188,7 +188,7 @@ namespace DotNetCore.CAP.MongoDB
return queryResult.Select(x => new MediumMessage
{
DbId = x.Id.ToString(),
Origin = _serializer.Deserialize(x.Content),
Origin = _serializer.Deserialize(x.Content)!,
Retries = x.Retries,
Added = x.Added
}).ToList();
@@ -209,7 +209,7 @@ namespace DotNetCore.CAP.MongoDB
return queryResult.Select(x => new MediumMessage
{
DbId = x.Id.ToString(),
Origin = _serializer.Deserialize(x.Content),
Origin = _serializer.Deserialize(x.Content)!,
Retries = x.Retries,
Added = x.Added
}).ToList();


+ 9
- 9
src/DotNetCore.CAP.MongoDB/StorageMessage.cs View File

@@ -9,13 +9,13 @@ namespace DotNetCore.CAP.MongoDB
{
public long Id { get; set; }

public string Version { get; set; }
public string Version { get; set; } = default!;

public string Group { get; set; }
public string Group { get; set; } = default!;

public string Name { get; set; }
public string Name { get; set; } = default!;

public string Content { get; set; }
public string Content { get; set; } = default!;

public DateTime Added { get; set; }

@@ -23,18 +23,18 @@ namespace DotNetCore.CAP.MongoDB

public int Retries { get; set; }

public string StatusName { get; set; }
public string StatusName { get; set; } = default!;
}

internal class PublishedMessage
{
public long Id { get; set; }

public string Version { get; set; }
public string Version { get; set; } = default!;

public string Name { get; set; }
public string Name { get; set; } = default!;

public string Content { get; set; }
public string Content { get; set; } = default!;

public DateTime Added { get; set; }

@@ -42,6 +42,6 @@ namespace DotNetCore.CAP.MongoDB

public int Retries { get; set; }

public string StatusName { get; set; }
public string StatusName { get; set; } = default!;
}
}

Loading…
Cancel
Save