-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional lifecycle registration changes (#1410)
* Added service lifetime to Jobs client Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Added service lifetime to messaging client Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Added service lifetime to actors registration Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Added unit tests for DaprClient Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Minor naming tweaks Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Removed invalid using Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Added service lifetime tests for actors Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Added unit tests for jobs client lifecycle registrations Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Added unit tests for PubSub and lifecycle registration Signed-off-by: Whit Waldo <whit.waldo@innovian.net> * Fixed missing registration dependency Signed-off-by: Whit Waldo <whit.waldo@innovian.net> --------- Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
- Loading branch information
Showing
7 changed files
with
352 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
test/Dapr.Actors.AspNetCore.Test/DaprActorServiceCollectionExtensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Dapr.Actors.AspNetCore.Test; | ||
|
||
public sealed class DaprActorServiceCollectionExtensionsTest | ||
{ | ||
[Fact] | ||
public void RegisterActorsClient_ShouldRegisterSingleton_WhenLifetimeIsSingleton() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddActors(options => { }, ServiceLifetime.Singleton); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var daprClient1 = serviceProvider.GetService<Runtime.ActorRuntime>(); | ||
var daprClient2 = serviceProvider.GetService<Runtime.ActorRuntime>(); | ||
|
||
Assert.NotNull(daprClient1); | ||
Assert.NotNull(daprClient2); | ||
|
||
Assert.Same(daprClient1, daprClient2); | ||
} | ||
|
||
[Fact] | ||
public async Task RegisterActorsClient_ShouldRegisterScoped_WhenLifetimeIsScoped() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddActors(options => { }, ServiceLifetime.Scoped); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
await using var scope1 = serviceProvider.CreateAsyncScope(); | ||
var daprClient1 = scope1.ServiceProvider.GetService<Runtime.ActorRuntime>(); | ||
|
||
await using var scope2 = serviceProvider.CreateAsyncScope(); | ||
var daprClient2 = scope2.ServiceProvider.GetService<Runtime.ActorRuntime>(); | ||
|
||
Assert.NotNull(daprClient1); | ||
Assert.NotNull(daprClient2); | ||
Assert.NotSame(daprClient1, daprClient2); | ||
} | ||
|
||
[Fact] | ||
public void RegisterActorsClient_ShouldRegisterTransient_WhenLifetimeIsTransient() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddActors(options => { }, ServiceLifetime.Transient); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var daprClient1 = serviceProvider.GetService<Runtime.ActorRuntime>(); | ||
var daprClient2 = serviceProvider.GetService<Runtime.ActorRuntime>(); | ||
|
||
Assert.NotNull(daprClient1); | ||
Assert.NotNull(daprClient2); | ||
Assert.NotSame(daprClient1, daprClient2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.