Skip to content

Commit

Permalink
Merge pull request #120 from autofac/external-dependency-switch
Browse files Browse the repository at this point in the history
Switch to ExternallyOwned for instance dependencies
  • Loading branch information
tillig authored Aug 11, 2024
2 parents dc03f10 + ecec468 commit eb20702
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
image: Ubuntu

version: 9.0.0.{build}
version: 10.0.0.{build}

dotnet_csproj:
version_prefix: '9.0.0'
version_prefix: '10.0.0'
patch: true
file: 'src\**\*.csproj'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ private static void Register(
builder
.RegisterInstance(descriptor.NormalizedImplementationInstance()!)
.ConfigureServiceType(descriptor)
.ConfigureLifecycle(descriptor.Lifetime, null);
.ConfigureLifecycle(descriptor.Lifetime, null)
.ExternallyOwned();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ public void ServiceScopesAreFlat()
innerScope.Dispose();
}

[Fact]
public void ServiceInstancesRegisteredAreNotDisposedWhenTheProviderIsDisposed()
{
var externalService = new DisposeTracker();
var services = new ServiceCollection().AddSingleton(externalService);
var rootProvider = CreateServiceProvider(services);
((IDisposable)rootProvider).Dispose();

Assert.False(externalService.Disposed);
}

protected abstract IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection);

[SuppressMessage("CA1812", "CA1812", Justification = "Instantiated through reflection.")]
Expand Down

0 comments on commit eb20702

Please sign in to comment.