AkkaNetContrib / Akka.DI.SimpleInjector

Akka.NET integration plugin for SimpleInjector dependency injection library
Apache License 2.0
10 stars 5 forks source link

Container lifestyle issues #12

Open feugen24 opened 6 years ago

feugen24 commented 6 years ago

In the implementation code "AsyncScopedLifestyle" is used but in the docs example it is not

// Setup Simple Injector
var container = new Container();
container.Register<IWorkerService, WorkerService>();

//this code should be added like in unit tests (set lifestyle for scoped registrations) container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

//and maybe even (default all registrations to scoped) container.Options.DefaultLifestyle = new AsyncScopedLifestyle();

since the alternative would be to set .Register<...>(Lifestyle.Scoped) for all registrations. If this is not set they will default to transient.

Another point is to have at least one test to check .Dispose() is called. A typical scenario is to have a Entity framework DbContext registered and it should be disposed at the end of the scope.

feugen24 commented 6 years ago

I tested and Dispose is called only if I stop/restart the actor that uses the dependency.