Skip to content

Commit c04aa9a

Browse files
committed
update to .NET + Orleans 7.0.0 GA, update example to Orleans.Results 1.0.0
1 parent a85bfe3 commit c04aa9a

File tree

14 files changed

+54
-59
lines changed

14 files changed

+54
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Secure, flexible tenant separation for Microsoft Orleans 7
55
> (install in silo client and grain implementation projects)
66
77
## Summary
8-
[Microsoft Orleans 7](https://github.com/dotnet/orleans/releases/tag/v7.0.0-rc2) is a great technology for building distributed, cloud-native applications. It was designed to reduce the complexity of building this type of applications for C# developers.
8+
[Microsoft Orleans 7](https://github.com/dotnet/orleans/releases/tag/v7.0.0) is a great technology for building distributed, cloud-native applications. It was designed to reduce the complexity of building this type of applications for C# developers.
99

1010
However, creating multi tenant applications with Orleans out of the box requires careful design, complex coding and significant testing to prevent unintentional leakage of communication or stored data across tenants. Orleans.Multitenant adds this capability to Orleans for free, as an uncomplicated, flexible and extensible API that lets developers:
1111

src/Example/Apis/Apis.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Microsoft.Orleans.Persistence.AzureStorage" Version="7.0.0-rc2" />
20-
<PackageReference Include="Microsoft.Orleans.Persistence.Memory" Version="7.0.0-rc2" />
21-
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0-rc2" />
22-
<PackageReference Include="Orleans.Multitenant" Version="1.0.0-rc2" />
23-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0-rc.2.22476.2" />
19+
<PackageReference Include="Microsoft.Orleans.Persistence.AzureStorage" Version="7.0.0" />
20+
<PackageReference Include="Microsoft.Orleans.Persistence.Memory" Version="7.0.0" />
21+
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0" />
22+
<PackageReference Include="Orleans.Multitenant" Version="1.0.0" />
23+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
2424
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
2525
</ItemGroup>
2626

src/Example/Apis/Foundation/ControllerBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Orleans;
2-
using Orleans.Multitenant;
1+
using Orleans.Multitenant;
32
using Orleans4Multitenant.Contracts.TenantContract;
43

54
namespace Orleans4Multitenant.Apis;

src/Example/Apis/Foundation/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.OpenApi.Models;
22
using Orleans.Configuration;
3-
using Orleans.Hosting;
43
using Orleans.Multitenant;
54
using Orleans.Storage;
65
using Orleans4Multitenant.Apis;

src/Example/Apis/TenantController.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class TenantController : ControllerBase
1111
const string Users = "users";
1212
const string UserId = "users/{id}";
1313

14-
public TenantController(Orleans.IClusterClient orleans) : base(orleans) { }
14+
public TenantController(IClusterClient orleans) : base(orleans) { }
1515

1616
/// <response code="200">The tenant has been updated</response>
1717
[HttpPut(Tenant)]
@@ -33,7 +33,7 @@ public async Task<Tenant> Get()
3333
public async Task<ActionResult<User>> CreateUser(User user)
3434
{
3535
var result = await RequestTenant.CreateUser(user);
36-
return result.TryAsValidationErrors(ErrorCode.ValidationError, out var validationErrors)
36+
return result.TryAsValidationErrors(ErrorNr.ValidationError, out var validationErrors)
3737
? ValidationProblem(new ValidationProblemDetails(validationErrors))
3838
: result switch
3939
{
@@ -56,9 +56,9 @@ public async Task<ActionResult<IEnumerable<User>>> GetUsers()
5656
public async Task<ActionResult<User>> GetUser(Guid id)
5757
=> await RequestTenant.GetUser(id) switch
5858
{
59-
{ IsSuccess: true } r => Ok(r.Value),
60-
{ ErrorCode: ErrorCode.UserNotFound } r => NotFound(r.ErrorsText),
61-
{ } r => throw r.UnhandledErrorException()
59+
{ IsSuccess: true } r => Ok(r.Value),
60+
{ ErrorNr: ErrorNr.UserNotFound } r => NotFound(r.ErrorsText),
61+
{ } r => throw r.UnhandledErrorException()
6262
};
6363

6464
/// <param name="id">must be equal to id in <paramref name="user"/></param>
@@ -72,9 +72,9 @@ public async Task<ActionResult> UpdateUser(Guid id, User user)
7272
=> id != user.Id ? BadRequest($"url id {id} != user id {user?.Id}") :
7373
await RequestTenant.UpdateUser(user) switch
7474
{
75-
{ IsSuccess: true } r => Ok(),
76-
{ ErrorCode: ErrorCode.UserNotFound } r => NotFound(r.ErrorsText),
77-
{ } r => throw r.UnhandledErrorException()
75+
{ IsSuccess: true } r => Ok(),
76+
{ ErrorNr: ErrorNr.UserNotFound } r => NotFound(r.ErrorsText),
77+
{ } r => throw r.UnhandledErrorException()
7878
};
7979

8080
/// <response code="200">If the user has been deleted</response>
@@ -85,8 +85,8 @@ public async Task<ActionResult> UpdateUser(Guid id, User user)
8585
public async Task<ActionResult> DeleteUser(Guid id)
8686
=> await RequestTenant.DeleteUser(id) switch
8787
{
88-
{ IsSuccess: true } r => Ok(),
89-
{ ErrorCode: ErrorCode.UserNotFound } r => NotFound(r.ErrorsText),
90-
{ } r => throw r.UnhandledErrorException()
88+
{ IsSuccess: true } r => Ok(),
89+
{ ErrorNr: ErrorNr.UserNotFound } r => NotFound(r.ErrorsText),
90+
{ } r => throw r.UnhandledErrorException()
9191
};
9292
}

src/Example/Contracts/Contracts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0-rc2" />
13+
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0" />
1414
</ItemGroup>
1515

1616
</Project>

src/Example/Contracts/Foundation/ErrorCode.cs renamed to src/Example/Contracts/Foundation/ErrorNr.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
namespace Orleans4Multitenant.Contracts;
22

3-
43
[Flags]
5-
public enum ErrorCode
4+
public enum ErrorNr
65
{
76
UserNotFound = 1,
87

src/Example/Contracts/Foundation/Result.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
// Version: 1.0.0-preview.2 (Using https://semver.org/)
2-
// Updated: 2022-08-26
1+
// Version: 1.0.0 (Using https://semver.org/)
2+
// Updated: 2022-11-10
33
// See https://github.com/Applicita/Orleans.Results for updates to this file.
44

55
using System.Diagnostics.CodeAnalysis;
6-
using Orleans;
76

87
namespace Orleans4Multitenant.Contracts;
98

109
/// <summary>
11-
/// Result without value; use to return either <see cref="Ok"/> or <see cref="ResultBase{ErrorCode}.Error"/>(s)
10+
/// Result without value; use to return either <see cref="Ok"/> or <see cref="ResultBase{ErrorNr}.Error"/>(s)
1211
/// </summary>
1312
[GenerateSerializer, Immutable]
14-
public class Result : ResultBase<ErrorCode>
13+
public class Result : ResultBase<ErrorNr>
1514
{
1615
public static Result Ok { get; } = new();
1716

@@ -21,16 +20,16 @@ public Result(IEnumerable<Error> errors) : base(ImmutableArray.CreateRange(error
2120
Result(Error error) : base(error) { }
2221

2322
public static implicit operator Result(Error error) => new(error);
24-
public static implicit operator Result(ErrorCode code) => new(code);
25-
public static implicit operator Result((ErrorCode code, string message) error) => new(error);
23+
public static implicit operator Result(ErrorNr nr) => new(nr);
24+
public static implicit operator Result((ErrorNr nr, string message) error) => new(error);
2625
public static implicit operator Result(List<Error> errors) => new(errors);
2726
}
2827

2928
/// <summary>
30-
/// Result with value; use to return either a <typeparamref name="TValue"/> or <see cref="ResultBase{ErrorCode}.Error"/>(s)
29+
/// Result with value; use to return either a <typeparamref name="TValue"/> or <see cref="ResultBase{ErrorNr}.Error"/>(s)
3130
/// </summary>
3231
[GenerateSerializer]
33-
public class Result<TValue> : ResultBase<ErrorCode, TValue>
32+
public class Result<TValue> : ResultBase<ErrorNr, TValue>
3433
{
3534
public Result(ImmutableArray<Error> errors) : base(errors) { }
3635
public Result(IEnumerable<Error> errors) : base(ImmutableArray.CreateRange(errors)) { }
@@ -39,13 +38,13 @@ public Result(IEnumerable<Error> errors) : base(ImmutableArray.CreateRange(error
3938

4039
public static implicit operator Result<TValue>(TValue value) => new(value);
4140
public static implicit operator Result<TValue>(Error error) => new(error);
42-
public static implicit operator Result<TValue>(ErrorCode code) => new(code);
43-
public static implicit operator Result<TValue>((ErrorCode code, string message) error) => new(error);
41+
public static implicit operator Result<TValue>(ErrorNr nr) => new(nr);
42+
public static implicit operator Result<TValue>((ErrorNr nr, string message) error) => new(error);
4443
public static implicit operator Result<TValue>(List<Error> errors) => new(errors);
4544
}
4645

4746
[GenerateSerializer]
48-
public abstract class ResultBase<TErrorCode, TValue> : ResultBase<TErrorCode> where TErrorCode : Enum
47+
public abstract class ResultBase<TErrorNr, TValue> : ResultBase<TErrorNr> where TErrorNr : Enum
4948
{
5049
[Id(0)] TValue? value;
5150

@@ -82,7 +81,7 @@ public TValue Value
8281
}
8382

8483
[GenerateSerializer]
85-
public abstract class ResultBase<TErrorCode> where TErrorCode : Enum
84+
public abstract class ResultBase<TErrorNr> where TErrorNr : Enum
8685
{
8786
public bool IsSuccess => !IsFailed;
8887
public bool IsFailed => errors?.Length > 0;
@@ -96,9 +95,9 @@ public abstract class ResultBase<TErrorCode> where TErrorCode : Enum
9695
public ImmutableArray<Error> Errors => errors ?? throw new InvalidOperationException("Attempt to access the errors of a success result");
9796

9897
/// <summary>
99-
/// Returns the errorcode for a failed result with a single error; otherwise throws an exception
98+
/// Returns the error nr for a failed result with a single error; otherwise throws an exception
10099
/// </summary>
101-
public TErrorCode ErrorCode => Errors.Single().Code;
100+
public TErrorNr ErrorNr => Errors.Single().Nr;
102101

103102
/// <summary>
104103
/// Returns all errors formatted in a single string for a failed result; throws an <see cref="InvalidOperationException"/> for a success result
@@ -111,14 +110,14 @@ public abstract class ResultBase<TErrorCode> where TErrorCode : Enum
111110
/// <remarks>Intended for use with <see cref="Microsoft.AspNetCore.Mvc.ValidationProblemDetails"/> (in MVC controllers) or <see cref="Microsoft.AspNetCore.Http.Results.ValidationProblem"/> (in minimal api's) </remarks>
112111
/// <param name="validationErrorFlag">The enum flag used to identify an error as a validation error</param>
113112
/// <param name="validationErrors">If the return value is true, receives all errors in a dictionary suitable for serializing into a https://tools.ietf.org/html/rfc7807 based format; otherwise set to null</param>
114-
/// <returns>True for a failed result that has the <paramref name="validationErrorFlag"/> set in the <typeparamref name="TErrorCode"/> for <b>all</b> errors; false otherwise</returns>
113+
/// <returns>True for a failed result that has the <paramref name="validationErrorFlag"/> set in the <typeparamref name="TErrorNr"/> for <b>all</b> errors; false otherwise</returns>
115114
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0001:Simplify Names", Justification = "Full name is necessary to ensure link works independently of global usings")]
116-
public bool TryAsValidationErrors(TErrorCode validationErrorFlag, [NotNullWhen(true)] out Dictionary<string, string[]>? validationErrors)
115+
public bool TryAsValidationErrors(TErrorNr validationErrorFlag, [NotNullWhen(true)] out Dictionary<string, string[]>? validationErrors)
117116
{
118-
if (IsFailed && Errors.All(error => error.Code.HasFlag(validationErrorFlag)))
117+
if (IsFailed && Errors.All(error => error.Nr.HasFlag(validationErrorFlag)))
119118
{
120119
validationErrors = new(Errors
121-
.GroupBy(error => error.Code, error => error.Message)
120+
.GroupBy(error => error.Nr, error => error.Message)
122121
.Select(group => new KeyValuePair<string, string[]>(group.Key.ToString(), group.ToArray())));
123122
return true;
124123
}
@@ -136,9 +135,9 @@ protected ResultBase() { }
136135
public NotImplementedException UnhandledErrorException(string? message = null) => new($"{message}Unhandled error(s): " + ErrorsText);
137136

138137
[GenerateSerializer, Immutable]
139-
public record Error([property: Id(0)] TErrorCode Code, [property: Id(1)] string Message = "")
138+
public record Error([property: Id(0)] TErrorNr Nr, [property: Id(1)] string Message = "")
140139
{
141-
public static implicit operator Error(TErrorCode code) => new(code);
142-
public static implicit operator Error((TErrorCode code, string message) error) => new(error.code, error.message);
140+
public static implicit operator Error(TErrorNr nr) => new(nr);
141+
public static implicit operator Error((TErrorNr nr, string message) error) => new(error.nr, error.message);
143142
}
144143
}

src/Example/Services.Tenant/Foundation/Errors.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
static class Errors
44
{
5-
internal static Result.Error UserNotFound(Guid id) => new(ErrorCode.UserNotFound, $"User {id} not found");
6-
internal static Result.Error IdIsNotEmpty(Guid id) => new(ErrorCode.IdIsNotEmpty, $"{id} is not the empty guid");
5+
internal static Result.Error UserNotFound(Guid id) => new(ErrorNr.UserNotFound, $"User {id} not found");
6+
internal static Result.Error IdIsNotEmpty(Guid id) => new(ErrorNr.IdIsNotEmpty, $"{id} is not the empty guid");
77
}

src/Example/Services.Tenant/Services.Tenant.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0-rc2" />
18-
<PackageReference Include="Orleans.Multitenant" Version="1.0.0-rc2" />
17+
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0" />
18+
<PackageReference Include="Orleans.Multitenant" Version="1.0.0" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

0 commit comments

Comments
 (0)