The current sample uses Unity, but the goal is to move away from a specific container and use the CoreCLR dependency injection abstractions.
- A
MyTestActor(id="MyCoolActor")
will be created, activated and 10secs later it will askMySecondTestActor
to do some work. - The MyTestActor(id="MyCoolActor") will be garbage collected after 120 seconds, see the registration in program.cs
- The MyTestActor(id="MyCoolActor") will be recreated, activated again each 3min and do the same as in 1.
- The MySecondTestActor(id="MyCoolActor") will be garbage collected after 30sec and recreated every 1 min due to its own reminder or every 3min due to the dowork call in 1.
- The MySecondTestActor(id="MyCoolActor") will every 1 min ask DependencyInjectionActorSample for its count, increase it by one and set it again.
Every new actor or service created will have a scoped container, such all scoped dependency registrations will be disposed if implementing IDisposable when the actor is garbage collected.
In Unity, you will register dependencies for scoped lifetime like this:
container.RegisterType<From,To>(new HierarchicalLifetimeManager());
- Remove dependency on unity
- Use CoreCLR dependency injection instead
- When dotnet core 1.1.0 is out, its possible to make services go from main.cs to startup.cs.