diff --git a/build.cake b/build.cake
index 013d3246b..a3a839a21 100644
--- a/build.cake
+++ b/build.cake
@@ -77,11 +77,13 @@ var packagesArtifactDirectory = artifactDirectory + "packages/";
var packageWhitelist = new[]
{
"Splat",
+ "Splat.Autofac",
};
var packageTestWhitelist = new[]
{
"Splat.Tests",
+ "Splat.Autofac.Tests",
};
var testFrameworks = new[] { "netcoreapp2.1", "net472" };
diff --git a/src/Splat.Autofac.Tests/DependencyResolverTests.cs b/src/Splat.Autofac.Tests/DependencyResolverTests.cs
new file mode 100644
index 000000000..055428dac
--- /dev/null
+++ b/src/Splat.Autofac.Tests/DependencyResolverTests.cs
@@ -0,0 +1,88 @@
+// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 Autofac;
+using ReactiveUI;
+using Shouldly;
+using Xunit;
+
+namespace Splat.Autofac.Tests
+{
+ ///
+ /// Tests to show the works correctly.
+ ///
+ public class DependencyResolverTests
+ {
+ ///
+ /// Shoulds the resolve views.
+ ///
+ [Fact]
+ public void AutofacDependencyResolver_Should_Resolve_Views()
+ {
+ var builder = new ContainerBuilder();
+ builder.RegisterType().As>();
+ builder.RegisterType().As>();
+ builder.Build().UseAutofacDependencyResolver();
+
+ var viewOne = Locator.Current.GetService(typeof(IViewFor));
+ var viewTwo = Locator.Current.GetService(typeof(IViewFor));
+
+ viewOne.ShouldNotBeNull();
+ viewOne.ShouldBeOfType();
+ viewTwo.ShouldNotBeNull();
+ viewTwo.ShouldBeOfType();
+ }
+
+ ///
+ /// Shoulds the resolve views.
+ ///
+ [Fact]
+ public void AutofacDependencyResolver_Should_Resolve_Named_View()
+ {
+ var builder = new ContainerBuilder();
+ builder.RegisterType().Named>("Other");
+ builder.Build().UseAutofacDependencyResolver();
+
+ var viewTwo = Locator.Current.GetService(typeof(IViewFor), "Other");
+
+ viewTwo.ShouldNotBeNull();
+ viewTwo.ShouldBeOfType();
+ }
+
+ ///
+ /// Shoulds the resolve view models.
+ ///
+ [Fact]
+ public void AutofacDependencyResolver_Should_Resolve_View_Models()
+ {
+ var builder = new ContainerBuilder();
+ builder.RegisterType().AsSelf();
+ builder.RegisterType().AsSelf();
+ builder.Build().UseAutofacDependencyResolver();
+
+ var vmOne = Locator.Current.GetService();
+ var vmTwo = Locator.Current.GetService();
+
+ vmOne.ShouldNotBeNull();
+ vmTwo.ShouldNotBeNull();
+ }
+
+ ///
+ /// Shoulds the resolve screen.
+ ///
+ [Fact]
+ public void AutofacDependencyResolver_Should_Resolve_Screen()
+ {
+ var builder = new ContainerBuilder();
+ builder.RegisterType().As().SingleInstance();
+ builder.Build().UseAutofacDependencyResolver();
+
+ var screen = Locator.Current.GetService();
+
+ screen.ShouldNotBeNull();
+ screen.ShouldBeOfType();
+ }
+ }
+}
diff --git a/src/Splat.Autofac.Tests/Mocks/MockScreen.cs b/src/Splat.Autofac.Tests/Mocks/MockScreen.cs
new file mode 100644
index 000000000..775a8fc43
--- /dev/null
+++ b/src/Splat.Autofac.Tests/Mocks/MockScreen.cs
@@ -0,0 +1,21 @@
+// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 ReactiveUI;
+
+namespace Splat.Autofac.Tests
+{
+ ///
+ /// An implementation.
+ ///
+ ///
+ public class MockScreen : IScreen
+ {
+ ///
+ /// Gets the Router associated with this Screen.
+ ///
+ public RoutingState Router { get; }
+ }
+}
diff --git a/src/Splat.Autofac.Tests/Mocks/ViewModelOne.cs b/src/Splat.Autofac.Tests/Mocks/ViewModelOne.cs
new file mode 100644
index 000000000..74379e18c
--- /dev/null
+++ b/src/Splat.Autofac.Tests/Mocks/ViewModelOne.cs
@@ -0,0 +1,23 @@
+// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 ReactiveUI;
+
+namespace Splat.Autofac.Tests
+{
+ ///
+ /// View Model One.
+ ///
+ ///
+ ///
+ public class ViewModelOne : ReactiveObject, IRoutableViewModel
+ {
+ ///
+ public string UrlPathSegment { get; }
+
+ ///
+ public IScreen HostScreen { get; }
+ }
+}
diff --git a/src/Splat.Autofac.Tests/Mocks/ViewModelTwo.cs b/src/Splat.Autofac.Tests/Mocks/ViewModelTwo.cs
new file mode 100644
index 000000000..96d2e1a6c
--- /dev/null
+++ b/src/Splat.Autofac.Tests/Mocks/ViewModelTwo.cs
@@ -0,0 +1,23 @@
+// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 ReactiveUI;
+
+namespace Splat.Autofac.Tests
+{
+ ///
+ /// View Model Two.
+ ///
+ ///
+ ///
+ public class ViewModelTwo : ReactiveObject, IRoutableViewModel
+ {
+ ///
+ public string UrlPathSegment { get; }
+
+ ///
+ public IScreen HostScreen { get; }
+ }
+}
diff --git a/src/Splat.Autofac.Tests/Mocks/ViewOne.cs b/src/Splat.Autofac.Tests/Mocks/ViewOne.cs
new file mode 100644
index 000000000..91e92ab23
--- /dev/null
+++ b/src/Splat.Autofac.Tests/Mocks/ViewOne.cs
@@ -0,0 +1,26 @@
+// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 ReactiveUI;
+
+namespace Splat.Autofac.Tests
+{
+ ///
+ /// View One.
+ ///
+ ///
+ public class ViewOne : IViewFor
+ {
+ ///
+ object IViewFor.ViewModel
+ {
+ get => ViewModel;
+ set => ViewModel = (ViewModelOne)value;
+ }
+
+ ///
+ public ViewModelOne ViewModel { get; set; }
+ }
+}
diff --git a/src/Splat.Autofac.Tests/Mocks/ViewTwo.cs b/src/Splat.Autofac.Tests/Mocks/ViewTwo.cs
new file mode 100644
index 000000000..4fe1a8274
--- /dev/null
+++ b/src/Splat.Autofac.Tests/Mocks/ViewTwo.cs
@@ -0,0 +1,27 @@
+// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 ReactiveUI;
+
+namespace Splat.Autofac.Tests
+{
+ ///
+ /// View Two.
+ ///
+ ///
+ [ViewContract("Other")]
+ public class ViewTwo : IViewFor
+ {
+ ///
+ object IViewFor.ViewModel
+ {
+ get => ViewModel;
+ set => ViewModel = (ViewModelTwo)value;
+ }
+
+ ///
+ public ViewModelTwo ViewModel { get; set; }
+ }
+}
diff --git a/src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj b/src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj
new file mode 100644
index 000000000..7c86cacb7
--- /dev/null
+++ b/src/Splat.Autofac.Tests/Splat.Autofac.Tests.csproj
@@ -0,0 +1,25 @@
+
+
+
+ netcoreapp2.1;net472
+
+ false
+ $(NoWarn);1591;CA1707;SA1633
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+
diff --git a/src/Splat.Autofac.Tests/xunit.runner.json b/src/Splat.Autofac.Tests/xunit.runner.json
new file mode 100644
index 000000000..42db7ef95
--- /dev/null
+++ b/src/Splat.Autofac.Tests/xunit.runner.json
@@ -0,0 +1,3 @@
+{
+ "shadowCopy": false
+}
diff --git a/src/Splat.Autofac/AutofacDependencyResolver.cs b/src/Splat.Autofac/AutofacDependencyResolver.cs
new file mode 100644
index 000000000..539e966cf
--- /dev/null
+++ b/src/Splat.Autofac/AutofacDependencyResolver.cs
@@ -0,0 +1,139 @@
+// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
+// Licensed to the .NET Foundation under one or more agreements.
+// 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;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Autofac;
+using Autofac.Core;
+
+namespace Splat.Autofac
+{
+ ///
+ /// Autofac implementation for .
+ ///
+ public class AutofacDependencyResolver : IMutableDependencyResolver
+ {
+ private IContainer _container;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The container.
+ public AutofacDependencyResolver(IContainer container)
+ {
+ _container = container;
+ }
+
+ ///
+ public virtual object GetService(Type serviceType, string contract = null)
+ {
+ try
+ {
+ return string.IsNullOrEmpty(contract)
+ ? _container.Resolve(serviceType)
+ : _container.ResolveNamed(contract, serviceType);
+ }
+ catch (DependencyResolutionException)
+ {
+ return null;
+ }
+ }
+
+ ///
+ public virtual IEnumerable