Skip to content
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

Keyed Services Support? 🤔 #596

Open
Mike-E-angelo opened this issue Aug 30, 2024 · 11 comments
Open

Keyed Services Support? 🤔 #596

Mike-E-angelo opened this issue Aug 30, 2024 · 11 comments

Comments

@Mike-E-angelo
Copy link

This issue piggybacks on this one:
seesharper/LightInject.Microsoft.DependencyInjection#210

I am beginning to wonder... is this a bigger problem? Does LightInject need to support Keyed Services? 🤔

@seesharper
Copy link
Owner

Hi @Mike-E-angelo

The problem here is a little bit more complicated than it might seem at first glance.
LightInject has always supported keyed/named services so one should think that this should work out of the box.
The problem is that LightInject.Microsoft.DependencyInjection does some , should we call it "dirty tricks" to make LightInject compatible with MS.DI. 😃 Some of those tricks involves an internal naming of services so that we for instance can bring back services in their registration order.
Take a look here
https://github.com/seesharper/LightInject.Microsoft.DependencyInjection/blob/9e5424007878ff0cf4b54ab9c0ce9402b4a36bc6/src/LightInject.Microsoft.DependencyInjection/LightInject.Microsoft.DependencyInjection.cs#L118

It ain't pretty,but it has worked up until now where MS.DI itself has started to support keyed services. Then those "hacks" would no longer work in all cases and the adapter breaks down.

So to fix this I've started to do some changes to LightInject itself to better adapt to MS.DI without using LightInject's named services as a way to be compatible with MS.DI.

I've started this work some time ago, but since nobody has asked for it yet , I pretty much left it on the shelf knowing that I would have to pick up on it eventually.

I guess that time is now. But just as you know, there is no easy fix here that can be solved in the adapter. Changes has to be made in LightInject to accommodate this.

@seesharper
Copy link
Owner

We probably end up with a new option in LightInject.
Something like ContainerOptions.EnableMicrosoftCompatibility or something like that.
Once that is in place and it passes all the tests from MS.DI with the option enabled it should be fairly easy to modify the adapter. In fact the adapter would be much simpler since we don't need to "adapt" so much anymore. 😃

@Mike-E-angelo
Copy link
Author

That sounds awesome @seesharper thank you for taking the time to comment and inform. I have to admit I am doing double-takes here because I am now shaking my head that "hey! DI has always had named services." ... 🤔 So these keyed services are different? I am so confused. 😅

I am of course more than happy to help test any new features that help address this problem. As I mentioned in the other thread an error is thrown currently but soon it will be null and that might lead to other issues.

@seesharper
Copy link
Owner

seesharper commented Sep 28, 2024

Hi @Mike-E-angelo . Just wanted to let you know that I have been working on this quite a lot the last couple of weeks. I have all the spec tests from MS working now. Still some cleanup needed, but we're getting there. Should be ready by the time .net 9 goes RTM 👍🙂

@Mike-E-angelo
Copy link
Author

That's awesome @seesharper! Thank you so very much for all your efforts out there. 🙏

@seesharper
Copy link
Owner

Thanks a lot for sponsoring me. 🤩. Really appreciate it.

@Mike-E-angelo
Copy link
Author

Right back atcha @seesharper ... thank you for being so responsive and engaging with your product. It has been fundamental and utilized by my framework for many years and is the least I can do. 🙏

@seesharper
Copy link
Owner

@Mike-E-angelo Hi Mike. Just wanted to give you an update on the progress here.
I'm pretty close to publishing a set of beta packages that you can try out.
All tests are passing and we are looking pretty good I think.
Minor cleanup left to do. Let you know as soon as the packages are available on Nuget.
In the meantime, have a great weekend 👍🍻

@Mike-E-angelo
Copy link
Author

Awesome @seesharper thank you very much for the update. For your awareness, the project I was working that was using Aspire (where I ran into this issue) has been put on hold for now, so this is not a rush/priority at the moment, but it would of course be great to have it there when I need it. 😊🙏 I appreciate all your work out there and wish a great weekend for you as well. 👍

@seesharper
Copy link
Owner

Hi @Mike-E-angelo
Just wanted to inform you that support for keyed services is now fully implemented.

The new packages are

  • LightInject 7.0.0
  • LightInject.Microsoft.DependencyInjection 4.0.0
  • LightInject.Microsoft.Hosting 2.0.0

Technically there are no breaking changes in these versions, but I decided to bump the major anyway 🙂

Again thanks for your sponsor contribution and for the encouragement ❤️

@Mike-E-angelo
Copy link
Author

That's really awesome @seesharper! Thank you again so very much for this. This will be very useful going forward to onboard the new tech such as Aspire which is using this feature. 🙏 I greatly appreciate all your efforts out there. 👍✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants