Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmach committed Feb 14, 2019
1 parent f50cd07 commit a9a5d1c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/Autofac/Core/Registration/ExternalRegistrySource.cs
Expand Up @@ -74,14 +74,6 @@ public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Fun
return _registry.RegistrationsFor(service)
.Where(r => r is ExternalComponentRegistration || !r.IsAdapting())
.Select(r =>
r as ExternalComponentRegistration ??
// equivalent to following registation builder
// RegistrationBuilder.ForDelegate(r.Activator.LimitType, (c, p) => c.ResolveComponent(r, p))
// .Targeting(r)
// .As(service)
// .ExternallyOwned()
// .CreateRegistration()
new ExternalComponentRegistration(
Guid.NewGuid(),
new DelegateActivator(r.Activator.LimitType, (c, p) => c.ResolveComponent(r, p)),
Expand Down
55 changes: 55 additions & 0 deletions test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs
Expand Up @@ -581,5 +581,60 @@ public void BeginLifetimeScopeCannotBeCalledWithDuplicateTag()

Assert.Equal(expectedMessage, exception.Message);
}

//issue 690
[Fact]
public void ParentRegistrationDidntDisposeByChildScope()
{
var builder = new ContainerBuilder();
builder.RegisterType<ServiceCFactory>().As<IServiceCFactory>().SingleInstance();
builder.Register(x => x.Resolve<IServiceCFactory>().CreateCService());
builder.RegisterType<ServiceE>();

var container = builder.Build();

using (var moduleScope = container.BeginLifetimeScope(x =>
{
x.RegisterType<ServiceD>().AsSelf().InstancePerLifetimeScope();
}))
{
var stub = moduleScope.Resolve<ServiceE>();
using (var syncScope = moduleScope.BeginLifetimeScope(y => y.RegisterInstance(stub).AsSelf().ExternallyOwned()))
{
syncScope.Resolve<ServiceD>();
}

stub = moduleScope.Resolve<ServiceE>();
}
}

interface IServiceCFactory
{
ServiceC CreateCService();
}

class ServiceC
{
}

class ServiceD
{
public ServiceD(ServiceC serviceC) { }
}

class ServiceE
{
public ServiceE(ServiceC serviceC) { }
}

class ServiceCFactory : IServiceCFactory
{
public ServiceC CreateCService()
{
return new ServiceC();
}
}


}
}

0 comments on commit a9a5d1c

Please sign in to comment.