diff --git a/src/Splat.Autofac.Tests/DependencyResolverTests.cs b/src/Splat.Autofac.Tests/DependencyResolverTests.cs index 055428dac..5afd57597 100644 --- a/src/Splat.Autofac.Tests/DependencyResolverTests.cs +++ b/src/Splat.Autofac.Tests/DependencyResolverTests.cs @@ -3,6 +3,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. +using System.Collections.Generic; +using System.Linq; using Autofac; using ReactiveUI; using Shouldly; @@ -84,5 +86,43 @@ public void AutofacDependencyResolver_Should_Resolve_Screen() screen.ShouldNotBeNull(); screen.ShouldBeOfType(); } + + /// + /// Shoulds register ReactiveUI binding type converters. + /// + [Fact] + public void AutofacDependencyResolver_Should_Register_ReactiveUI_BindingTypeConverters() + { + // Invoke RxApp which initializes the ReactiveUI platform. + var scheduler = RxApp.MainThreadScheduler; + var builder = new ContainerBuilder(); + var container = builder.Build(); + Locator.Current = new AutofacDependencyResolver(container); + + var converters = container.Resolve>().ToList(); + + converters.ShouldNotBeNull(); + converters.ShouldContain(x => x.GetType() == typeof(StringConverter)); + converters.ShouldContain(x => x.GetType() == typeof(EqualityTypeConverter)); + } + + /// + /// Shoulds register ReactiveUI creates command bindings. + /// + [Fact] + public void AutofacDependencyResolver_Should_Register_ReactiveUI_CreatesCommandBinding() + { + // Invoke RxApp which initializes the ReactiveUI platform. + var scheduler = RxApp.MainThreadScheduler; + var builder = new ContainerBuilder(); + var container = builder.Build(); + Locator.Current = new AutofacDependencyResolver(container); + + var converters = container.Resolve>().ToList(); + + converters.ShouldNotBeNull(); + converters.ShouldContain(x => x.GetType() == typeof(CreatesCommandBindingViaEvent)); + converters.ShouldContain(x => x.GetType() == typeof(CreatesCommandBindingViaCommandParameter)); + } } } diff --git a/src/Splat.Autofac/AutofacDependencyResolver.cs b/src/Splat.Autofac/AutofacDependencyResolver.cs index 539e966cf..7a4ac6f47 100644 --- a/src/Splat.Autofac/AutofacDependencyResolver.cs +++ b/src/Splat.Autofac/AutofacDependencyResolver.cs @@ -6,6 +6,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Autofac; using Autofac.Core; @@ -70,6 +71,7 @@ public virtual IEnumerable GetServices(Type serviceType, string contract /// The factory function which generates our object. /// The type which is used for the registration. /// A optional contract value which will indicates to only generate the value if this contract is specified. + [SuppressMessage("Design", "CS0168: Obsolete method call", Justification = "Needed for container generation")] public virtual void Register(Func factory, Type serviceType, string contract = null) { var builder = new ContainerBuilder(); @@ -81,6 +83,8 @@ public virtual void Register(Func factory, Type serviceType, string cont { builder.Register(x => factory()).Named(contract, serviceType).AsImplementedInterfaces(); } + + builder.Update(_container); } ///