-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Using LightInject with ASP.Net vNext #132
Comments
Hi Eric. I understand that you live on the bleeding edge from a technological point When it comes to ASP.Net vNext, I have not looked into this yet as it seems I could not help but notice that you have committed something similar for Do you know if it is possible to run any of this in Visual Studio 2013? Anyway, I appreciate the effort and I will take a look at it as soon as I Best regards Bernhard Richter On Tue, Nov 18, 2014 at 4:51 PM, Swannee [email protected] wrote:
|
Hey Bernhard...yeah I was also playing with SimpleInjector as that is another DI container I like :). As you mentioned, I ran into some similar issues with SimpleInjector so thought I'd try my luck with LightInject. Both of them have similar issues in this vein, but frankly I feel that LightInject has a simpler approach to some things (in a good way) and that might make it easier. The main reason I'm trying out VS 2015 is that I really like the "combined aspnet" and the unified DI concepts. In addition, I was also trying out their Cordova project time so decided to jump in feet first. There really is a lot of truly exciting stuff in this release. I do have to warn you that VS 2015 is still pretty buggy in the intellisense area and if you use Resharper as I do, it's also very buggy (but kinda works). The core stuff all seems really solid though. Any help will be appreciated...I'll continue to work through the other failing tests and see where I get. |
Hey Bernhard...did you ever try this out with vNext? I hear it's going to drop ~mid-year...I basically ran into a wall with the primary issue I had here:
So a scope is created, and the test asks for an instance from the main container (which it expects to be unscoped) and it then it asks for an instance from the scope (which essentially amounts to a child container) and expects it to be different. But LightInject doesn't really have a child container concept that I can see. Once I start a scope, my original LightInject container also operates within that scope. |
I might have to look into adding support for child containers in order to support this scenario. |
Hi @seesharper. I would also be very interested in child container support. I am wanting a fresh child container per test, so that I can override registrations in a test, and then have them disposed at the end of the test. Is that something I can do already with scopes, or would the new child container support be the only way to achieve that? Thanks. |
Now that ASP.NET 5 RC1 is out and production ready, what is the status of ASP.NET 5 support in LightInject? Strongly considering migrating to ASP.NET 5, would like to have my favourite DI library on board :) |
LightInject is already set up for dnxcore50 (CoreCLR) and dnx451. The On Monday, 23 November 2015, Geir Sagberg [email protected] wrote:
|
Seems it was moved to the RC2 milestone: aspnet/DependencyInjection#270, although it's marked as closed. No NuGet package found yet though. I'll see what I can do with eswann's fork in the meantime :) |
Nevermind, it is on the myget feed: https://www.myget.org/F/aspnetvnext/api/v2/package/Microsoft.Extensions.DependencyInjection.Specification.Tests/1.0.0-rc2-15807 |
Do you know if there is one for RC1. They are still making breaking changes (renaming methods and so forth) in the dev branch for RC2. I could of course do an implementation based on RC2, but that would probably not even compile on RC1. As much as would love to get my hands dirty on this one I feel that this is still a moving target to say the least. |
The earliest build is 1.0.0-rc2-15788 it seems. I understand if you are reluctant to start implementing support until things have stabilized more; I believe the ASP.NET team mentioned a possible ETA for RC2 in January on a community standup, perhaps this issue might have to wait until then. What kind of implementation changes to LightInject do you think will be needed for full support? I assume the child container issue is still relevant? In any case I will give it a go on making the tests pass; will post here if I succeed. |
I don't really think any changes to the container are required. The child container behavior can easily be implemented using scopes. Or at least it seemed so the last time I checked. Regardless of the RC2 ETA, trying to write an adapter now would be a good exercise and it would probably require just minor changes to line up with the RC2/RTM version of ASP.NET 5. |
I got all tests passing now. Question is ..what should the Nuget package be called? -- Microsoft.Extensions.DependencyInjection.LightInject ? This might be good for searching Nuget -- LightInject.AspNet? LightInject.DependencyInjection? |
Decision made. LightInject.Microsoft.DependencyInjection it is. https://github.com/seesharper/LightInject.Microsoft.DependencyInjection |
Good stuff! I agree on the package naming, keeps it under the LightInject namespace but makes it obvious that this is connected to the new Microsoft DI standard. |
Here is the first pre release version Also available from Nuget |
Hi Berhard, I was trying out some IOC containers with ASP.Net vNext, and thought I'd try to implement the built in DI using LightInject, as it's one of the DI containers I like. There's already an opensource project on Github hosted by M$ for this purpose. It has a few of the popular containers implemented and has a base set of tests that it runs on all containers. (https://github.com/aspnet/DependencyInjection)
I've created a fork and made an attempt to implement this with LightInject, (https://github.com/eswann/DependencyInjection) but I've got several failing tests to work out and I'm stuck on one failing test in particular. It's essentially a scope issue. I'm guessing there's a decent way to handle this. There is a test (ScopedServiceCanBeResolved) which basically goes like:
So a scope is created, and the test asks for an instance from the main container (which it expects to be unscoped) and it then it asks for an instance from the scope (which essentially amounts to a child container) and expects it to be different. But LightInject doesn't really have a child container concept that I can see. Once I start a scope, my original LightInject container also operates within that scope.
There are two main interfaces that have to be implemented: IServiceScope and IServiceScopeFactory.
The scope is a common interface that I had to implement and I just for now have it just wrapping an LI IServiceFactory and creating/disposing a new scope. But obviously this doesn't meet the requirements of the DI tests. Whether or not this is important...I don't really know but passing all of the provided tests would probably be a good idea.
Anyway...any ideas on how to accomplish this would be appreciated.
Thanks!
Eric
The text was updated successfully, but these errors were encountered: