reactiveui/splat

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

jposert opened this issue · 6 comments

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

relates to #240

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;

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.

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

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.

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.