-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
feature: Add Microsoft.Extensions.DependencyInjection adapter #362
Comments
There are few things different in Msft DI, in my own project I implemented it the way I found as right but if I'm to PR, I better consult with you guys. A resolver isn't mutableIn Msft DI, there is no mutable-resolver. There is either configurator or resolver, once the provider is built, it's locked up and you can no longer inject new services. What I've done is added an intermediate interface No registration with string contractsMsft doesn't provide Should we completely ignore the parameter, raise an exception if it's provided? |
David has got around point 1 by rebuilding the locator instance with other resolvers. Second point you have scoped operations in ms di extensions which are attempting to do the same thing as contracts. |
What do you mean? In Splat, during the configure container stage there are calls to the provider (for logging). MS doesn't support this. How do you notify the resolver that its provider is different? |
See
Essentially unregister on autofac will scan through all items registered. Create a fresh container. Add back all services but the one removed. |
If that's not feasible then exception is fine |
I'm not familiar with AutoFac, but is it also that there is a 'build' point that the service collection gets locked up? |
Yep most do that. Our general idea it should stop being mutable when you run the extension method to register it with splat |
You can't do that, because while splat registers its services, it also tries to consume some of them (for example loggers). |
Every di we offer btw has a extension method to set it as the di engine inside splat. |
So until that point it doesn't attempt to consume it. |
Wouldn't it be better to dedicate a special interface that provides this 'override'? |
Nope. This keeps it consistent |
Oh, I see now. It's the same ex. method over the container. Looks good and less verbose than an interface indeed. |
So yeah. The idea is you do all your registration either in the splat override or your native di, use the extension method and after that point it's immutable |
How to implement |
Add () is a similar mechanism |
autofac's builder.update method is actually obsolete, so the "unregister" rebuild logic will probably have to to be used by add at some point |
That was the problem I ran into with Simple Injector. The container is only built once. I thought I found away around it, but I let the branch go stale for other priorities. I thought you had a working implementation? This should be no more difficult than hooking your working solution into the same structure as the other DI Adapters already implemented. All the code is generally the same. There is also some work going on that may change how some of the adapters are implemented. So you might want to be aware to reduce additional efforts. I'll dig up that branch and see if it can provide a baseline. |
I think all these containers will be way easier if we just make it immutable with the extension method. |
Does it look any better now? |
One minor observation, it's usually better to work on a branch off master for pull requests. Looks closer to what I was imagining. |
Will remember that in the future.
So can I focus on making some tests? |
just a heads up. I was looking at your branch. your unit test project csproj can be simplified. the directoy.build.props detects test projects and includes xunit etc. also the main unit test package uses msbuild.extras - I would just compare one of the others and tweak :) also I've included a base unit test class for some of the repeatable tests. |
Add a Microsoft.Extensions.DependencyInjection package
Relates To: #233
The text was updated successfully, but these errors were encountered: