MutableResolver dependency resolver samples

282 views
Skip to first unread message

Ozan Yurtseven

unread,
Jul 2, 2014, 6:47:47 AM7/2/14
to reacti...@googlegroups.com
I'm starting to learn and use ReactiveUI after Mvvmlight. At mvvmlight and structuremap I can register with dependencies like this

SimpleIoc.Default.Register<IRequestService,RequestService>();
 SimpleIoc.Default.Register<IAuthenticationRepository,AuthenticationRepository>();


How can I do with ReactiveUI dependency resolver. My problem is AuthenticationRepository depend on RequestService. I use constructor dependency.

Thanks in advance.

Stas Shusha

unread,
Jul 2, 2014, 7:52:37 AM7/2/14
to reacti...@googlegroups.com
Hi, you could easily substitute default Resolver with your own. Here is an example of what I did with NInject:
            //Set up NInject to do DI
            var customResolver = new FuncDependencyResolver(
                (service, contract) =>
                {
                    if (contract != null) return kernel.GetAll(service, contract);
                    var items = kernel.GetAll(service);
                    var list = items.ToList();
                    return list;
                },
                (factory, service, contract) =>
                {
                    var binding = kernel.Bind(service).ToMethod(_ => factory());
                    if (contract != null) binding.Named(contract);
                });

                Locator.Current = customResolver;

Note: "kernel" is NInject container instance


--
You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivexaml...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ozan Yurtseven

unread,
Jul 3, 2014, 4:08:45 AM7/3/14
to reacti...@googlegroups.com
Thanks.

And this code needs to be under appbootstrapper? After this change is it the same view and viewmodel resolving

dependencyResolver.Register(() => new MainView(), typeof(IViewFor<MainViewModel>));

This code needs to be same or I need to change this ninject resolving. And How can I use kernel internal resolving and where? Sorry for my english I hope you can understand me.

Stas Shusha

unread,
Jul 3, 2014, 2:32:02 PM7/3/14
to reacti...@googlegroups.com
Yeah, AppBootstrapper is a good place for component registrations. You could perform all your registration as you usually do with your favorite DI container (SimpleIoC for example) and then wrap it with FuncDependencyResolver to substitute the default one via Locator.Current as I shown you in previous email (it is needed for RxUI stuff registration).

Good luck, Stas.
Reply all
Reply to author
Forward
0 new messages