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

[Suggestion] Create extension using Microsoft.Extensions.DependencyInjection.Abstractions #2

Closed
schodemeiss opened this issue Apr 20, 2019 · 3 comments

Comments

@schodemeiss
Copy link

It would be nice if we could create an Adaptor or Extension for Extenject that extends the Microsoft.Extensions.DependencyInjection.Abstractions lib. That way, we can rely on an abstracted DIContainer rather than binding our game projects directly to Extenject. However, I appreciate there's a lot of Unity specific things in Extenject.

Other DI's have done this, so I'm sure it's possible. Please see: https://github.com/aspnet/Extensions/tree/master/src/DependencyInjection

@svermeulen
Copy link

Agreed

@KuraiAndras
Copy link

I'm currently working on a solution for this, but i hit some conceptual problems I can't seem to solve.

Working but not ideal solution
The problem: this works, but it requires instantiation of every type which is registered with a factory method(see line 24), which is not a desired solution and could cause problems(ie.: singleton classes which contains constructor logic that is expected to run at the time of first instantiation).

Not working solution, seems ideal but don't understand the problem.

When I try to register a service which is registered with an implementation factory i hit a binding assert stating: Expected type 'object' to derive from type 'IExampleInterface'
(see line 22)

I know the registration is working, im experimenting with a service collection which is already working in a wpf application where we just use the IServiceProvider.

Any idea how to solve this? I don't really understand why this happens with from method.
Also tried:

binding = Container.Bind(service.ServiceType).FromMethod(_ => { var implementation = service.ImplementationFactory(serviceProvider); return Convert.ChangeType(implementation, implementation.GetType()); });

Which did not help either and produced the same error message

@KuraiAndras
Copy link

KuraiAndras commented Nov 28, 2020

So, fast forward 10 months, I have managed to solve this. The package is available on Github and OpenUPM.

@schodemeiss schodemeiss closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2022
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

3 participants