-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Akka.NET Dependency Injection testkit for #942 #1139
Conversation
See #942 for the original discussion. |
Here's the set of tests that we run for each DI framework as part of Akka.DI.TestKit;
|
So, the discussion. Akka.DI Behavior AssumptionsThese tests make the following assumptions about how
Right now, 100% of Akka.DI implementations fail assumption 3. And CastleWindsor fails assumption 1 as well (and, in fact, currently crashes the XUnit2 test runner.) Decisions that must be madeWe have to do both of the following:
Some of these issues are a matter of just configuring the container "correctly." We need to document what that looks like for each framework once the assumptions are decided upon. So let's start that discussion now: cc @akkadotnet/developers @akkadotnet/contributors |
f5537b8
to
7914cd3
Compare
Following on from the discussion on gitter. I agree with all of the assumptions listed above, as discussed it seems as though we are not in the case of say Autofac attaching a lifetime scope to the lifetime of the ActorBase. The hook for disposing components should be on both Restart and Terminate, any new instance of an actor is created within a new scope and any time the actor goes away whether it is a restart or termination we dispose this scope and then create a new scope upon creating the new actor instance. |
7914cd3
to
bf6de9b
Compare
I agree with almost all the assumptions outlined by @Aaronontheweb . Except for number 3. If resources are managed by an container, they should also be disposed by the container. Even though it would be possible to manually dispose them in the |
👍 on what @Danthar said. |
I got a little confused by this:
Why does Akka care which instance of a dependency is injected into an actor? Seems to me this depends only on the scope of the registered dependency. Akka shouldn't expect always a new instance to be injected. It should just accept whatever the container gives to it, and that may vary depending on the defaults of the framework you're using. |
Not referring to DI container lifecycles in this test. In fact, I'm ensuring that they are respected. What I wanted to avoid is having
Ok, so it seems like @Danthar and @rogeralsing take issue with this specific part of issue 3
I was considering adding some overridable behavior inside |
So I updated the DI implementation to call Current test results: cc @akkadotnet/contributors so I need help. We need to determine what the recommended DI configuration is for each DI framework in order to pass these specifications. People can choose not to use that recommendation if they want, but I think this is pretty essential to make clear. These DI frameworks were mostly designed for ASP.NET, and Akka.NET actors can have much longer lifespans than those objects. |
In order to help, you'll need to clone my branch here https://github.com/Aaronontheweb/akka.net/tree/di-testkit-squash and send PRs to it - wouldn't be the first time we've done something like that :p |
@Aaronontheweb On castle you can try setting the release policy not to track along with registration of transient which you already doing. Check this link. http://stackoverflow.com/questions/85183/windsor-container-how-to-force-dispose-of-an-object |
@jcwrequests senor @stefansedich just left a comment on #942 which explains all of the container configurations he used to get the tests to pass, plus some bug fixes. Mind taking a look through those and let me know if you approve of setting those as the "recommended figuration" for working with Akka.NET actors and DI? |
@Aaronontheweb I just saw that. On my phone at the moment but I will see what I can do.Did you try his changes against your tests? He certainly knows his stuff. |
@jcwrequests yep, got a green check mark now! |
Awesome. That Aussie rocks. I will double check but He really knows his way around DI and I can't imagine and issues. |
3751f87
to
994ba98
Compare
994ba98
to
5fd1c04
Compare
Where is the thread with the more detaled discussion? has that been closed? |
Should be over in #942 @rogeralsing. @Aaronontheweb we ready to just YOLO this one and merge it in? I will get onto the doco side of it as soon as I can. |
@stefansedich I would - any longer term discussions about the role of DI in Akka.NET aren't relevant to the scope of this PR. Ship it! |
Akka.NET Dependency Injection testkit for #942
I'd be interested to see how this unofficial DI container compares: https://simpleinjector.org/index.html Bindings: https://github.com/AkkaNetContrib/Akka.DI.SimpleInjector |
Do not merge. There will be test failures.
This PR introduces
Akka.DI.TestKit
, which will be available as a NuGet package, and introduces the following test libraries:Based on what I've been able to recreate locally using my development machine, I've found that our DI system currently leaks injected resources and there's a lot of inconsistencies across DI framework implementations as to whether or not they clean up
IDisposable
resources from terminated actors.We'll use the results from the CI server to create a discussion here on what the expected and recommended behavior for DI inside Akka.NET should be.
Some containers may have to use additional options that are specific to the container's configuration in order to achieve these goals. That's fine, but we have to document what those are and explicitly list them on http://getakka.net/ as official project recommendations when working with specific DI libraries.