diff --git a/appveyor.yml b/appveyor.yml index 88e53d7..f760ac4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,11 @@ -version: 3.3.3.{build} +version: 3.3.4.{build} assembly_info: patch: true file: AssemblyInfo.cs assembly_version: "3.3.0.0" assembly_file_version: "{version}" - assembly_informational_version: "3.3.3-CI-{build}" + assembly_informational_version: "3.3.4-CI-{build}" configuration: Release diff --git a/src/Autofac.Integration.Mvc/AutofacDependencyResolver.cs b/src/Autofac.Integration.Mvc/AutofacDependencyResolver.cs index 57922b9..adae505 100644 --- a/src/Autofac.Integration.Mvc/AutofacDependencyResolver.cs +++ b/src/Autofac.Integration.Mvc/AutofacDependencyResolver.cs @@ -149,7 +149,7 @@ public ILifetimeScope ApplicationContainer /// Type of the service. /// The single instance if resolved; otherwise, null. [SecurityCritical] - public object GetService(Type serviceType) + public virtual object GetService(Type serviceType) { return RequestLifetimeScope.ResolveOptional(serviceType); } @@ -160,7 +160,7 @@ public object GetService(Type serviceType) /// Type of the service. /// The list of instances if any were resolved; otherwise, an empty list. [SecurityCritical] - public IEnumerable GetServices(Type serviceType) + public virtual IEnumerable GetServices(Type serviceType) { var enumerableServiceType = typeof(IEnumerable<>).MakeGenericType(serviceType); var instance = RequestLifetimeScope.Resolve(enumerableServiceType); diff --git a/tests/Autofac.Tests.Integration.Mvc/AutofacDependencyResolverFixture.cs b/tests/Autofac.Tests.Integration.Mvc/AutofacDependencyResolverFixture.cs index 865c1a4..81ee246 100644 --- a/tests/Autofac.Tests.Integration.Mvc/AutofacDependencyResolverFixture.cs +++ b/tests/Autofac.Tests.Integration.Mvc/AutofacDependencyResolverFixture.cs @@ -24,6 +24,7 @@ // OTHER DEALINGS IN THE SOFTWARE. using System; +using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Autofac.Integration.Mvc; @@ -147,9 +148,11 @@ public void ConfigurationActionInvokedForNestedLifetime() public void DerivedResolverTypesCanStillBeCurrentResolver() { var container = new ContainerBuilder().Build(); - var provider = new DerivedAutofacDependencyResolver(container); - DependencyResolver.SetResolver(provider); - Assert.AreEqual(provider, AutofacDependencyResolver.Current, "You should be able to derive from AutofacDependencyResolver and still use the Current property."); + var resolver = new DerivedAutofacDependencyResolver(container); + DependencyResolver.SetResolver(resolver); + Assert.AreEqual(resolver, AutofacDependencyResolver.Current, "You should be able to derive from AutofacDependencyResolver and still use the Current property."); + Assert.That(resolver.GetService(typeof(object)), Is.Not.Null); + Assert.That(resolver.GetServices(typeof(object)), Has.Length.EqualTo(1)); } [Test] @@ -206,9 +209,18 @@ public void GetServicesReturnsRegisteredService() private class DerivedAutofacDependencyResolver : AutofacDependencyResolver { - public DerivedAutofacDependencyResolver(IContainer container) - : base(container, new StubLifetimeScopeProvider(container)) + public DerivedAutofacDependencyResolver(IContainer container) : base(container) + { + } + + public override object GetService(Type serviceType) + { + return serviceType == typeof(object) ? new object() : base.GetService(serviceType); + } + + public override IEnumerable GetServices(Type serviceType) { + return serviceType == typeof(object) ? new[] {new object()} : base.GetServices(serviceType); } } }