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

[BUG] Splat.SimpleInjector - not possible to do a setup. #597

Closed
jposert opened this issue Sep 29, 2020 · 6 comments · Fixed by #631
Closed

[BUG] Splat.SimpleInjector - not possible to do a setup. #597

jposert opened this issue Sep 29, 2020 · 6 comments · Fixed by #631
Labels

Comments

@jposert
Copy link
Contributor

jposert commented Sep 29, 2020

It's not possible to use SimpleInjector as a DI container because of sole "Resolves" of the ReactiveUI during initialization.

Steps To Reproduce
Splat.SimpleInjector (9.5.49)
RxUI (11.5.35)

var container = new Container();
Locator.SetLocator(new SimpleInjectorDependencyResolver(container));

var resolver = Locator.CurrentMutable;
resolver.InitializeSplat();
resolver.InitializeReactiveUI();

In line:
resolver.InitializeReactiveUI();
System.InvalidOperationException exception occurs.

System.InvalidOperationException: 'Type ICreatesObservableForProperty has already been registered. If your intention is to resolve a collection of ICreatesObservableForProperty implementations, use the Container.Collection.Register overloads. For more information, see https://simpleinjector.org/coll1. If your intention is to replace the existing registration with this new registration, you can allow overriding the current registration by setting Container.Options.AllowOverridingRegistrations to true. For more information, see https://simpleinjector.org/ovrrd.'

The problem occurs because in RxApp static constructor there's Splat.LogHost.Default used - and it calls Locator.Current.GetService<ILogManager>() on the container.

And problem occurs because of the first use of "GetInstance" method on the SimpleInjector - it's sealed.

Expected behavior
Allow to use SimpleInjector.

Environment(please complete the following information):

  • OS: Windows
  • Version: 10
@dpvreony
Copy link
Member

relates to #240

@MohammadSadeghSalimian
Copy link

You need to change AllowOverridingRegistrations to true in the Options property of your container. Although you can soleve your exception at this stage, you will face another problem on another stage.

_container.Options.AllowOverridingRegistrations = true;

@MohammadSadeghSalimian
Copy link

MohammadSadeghSalimian commented Nov 15, 2020

There is another bug with simple injector. If your main window has RoutedViewHost you will face an error when your window in initializng: At presetnt, I faied to find a way to solve this error. It seems some interfaces are not registered.

ActivationException: No registration for type IEnumerable could be found. There is, however, a registration for IActivationForViewFetcher; Did you mean to call GetInstance() or depend on IActivationForViewFetcher? Or did you mean to register a collection of types using Container.Collection.Register? Please see https://simpleinjector.org/collections for more information about registering and resolving collections.

@glennawatson
Copy link
Contributor

Might be worth making a new issue about that found bug.

@jposert
Copy link
Contributor Author

jposert commented Nov 15, 2020

Hi Guys!
Because I really like SimpleInjector I decided to try to make it work with ReactiveUI. Please check my PR #631. I use the solution on my small "home" WPF project and for now i havent encountered any problems.

To "solve" problems with collection, i decided to treat every dependency as a collection dependency. So far so good... all works but to be hones, i have no clue about possible performance issues.

Also, in order to make ReactiveUI initialization to work, i had to create some kind of intermediate "dummy" container which collect's all the initializations dependencies.

@dpvreony dpvreony linked a pull request Nov 20, 2020 that will close this issue
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants