diff --git a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacServiceProvider.cs b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacServiceProvider.cs
index ff2d45b2a4..1c1a24ff66 100644
--- a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacServiceProvider.cs
+++ b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacServiceProvider.cs
@@ -1,6 +1,6 @@
// This software is part of the Autofac IoC container
// Copyright © 2015 Autofac Contributors
-// http://autofac.org
+// https://autofac.org
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -33,19 +33,21 @@ namespace Autofac.Extensions.DependencyInjection
///
///
///
- public class AutofacServiceProvider : IServiceProvider, ISupportRequiredService
+ public class AutofacServiceProvider : IServiceProvider, ISupportRequiredService, IDisposable
{
- private readonly IComponentContext _componentContext;
+ private readonly ILifetimeScope _lifetimeScope;
+
+ private bool _disposed = false;
///
/// Initializes a new instance of the class.
///
- ///
- /// The component context from which services should be resolved.
+ ///
+ /// The lifetime scope from which services will be resolved.
///
- public AutofacServiceProvider(IComponentContext componentContext)
+ public AutofacServiceProvider(ILifetimeScope lifetimeScope)
{
- this._componentContext = componentContext;
+ this._lifetimeScope = lifetimeScope;
}
///
@@ -66,7 +68,7 @@ namespace Autofac.Extensions.DependencyInjection
///
public object GetRequiredService(Type serviceType)
{
- return this._componentContext.Resolve(serviceType);
+ return this._lifetimeScope.Resolve(serviceType);
}
///
@@ -81,7 +83,40 @@ namespace Autofac.Extensions.DependencyInjection
///
public object GetService(Type serviceType)
{
- return this._componentContext.ResolveOptional(serviceType);
+ return this._lifetimeScope.ResolveOptional(serviceType);
+ }
+
+ ///
+ /// Gets the underlying instance of .
+ ///
+ public ILifetimeScope LifetimeScope => _lifetimeScope;
+
+ ///
+ /// Releases unmanaged and - optionally - managed resources.
+ ///
+ ///
+ /// to release both managed and unmanaged resources;
+ /// to release only unmanaged resources.
+ ///
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!this._disposed)
+ {
+ this._disposed = true;
+ if (disposing)
+ {
+ this._lifetimeScope.Dispose();
+ }
+ }
+ }
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ public void Dispose()
+ {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
}
}
}
\ No newline at end of file