-
-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #847: ScopeRestrictedRegistry now also applies ComponentRegistr…
…ationLifetimeDecorator to registrations from registration sources.
- Loading branch information
Showing
4 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
test/Autofac.Test/Core/Registration/ScopeRestrictedRegistryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Autofac.Builder; | ||
using Autofac.Core; | ||
using Autofac.Core.Registration; | ||
using Xunit; | ||
|
||
namespace Autofac.Test.Core.Registration | ||
{ | ||
public sealed class ScopeRestrictedRegistryTests | ||
{ | ||
private static readonly IComponentRegistration ObjectRegistration = | ||
RegistrationBuilder.ForType<object>().SingleInstance().CreateRegistration(); | ||
|
||
private class ObjectRegistrationSource : IRegistrationSource | ||
{ | ||
public IEnumerable<IComponentRegistration> RegistrationsFor( | ||
Service service, | ||
Func<Service, IEnumerable<IComponentRegistration>> registrationAccessor) | ||
{ | ||
yield return ObjectRegistration; | ||
} | ||
|
||
public bool IsAdapterForIndividualComponents => false; | ||
} | ||
|
||
[Fact] | ||
public void SingletonsFromRegistrationSourceAreWrappedWithLifetimeDecorator() | ||
{ | ||
var registry = new ScopeRestrictedRegistry(new object(), new Dictionary<string, object>()); | ||
|
||
registry.AddRegistrationSource(new ObjectRegistrationSource()); | ||
|
||
var typedService = new TypedService(typeof(object)); | ||
registry.TryGetRegistration(typedService, out IComponentRegistration registration); | ||
|
||
Assert.IsType<ComponentRegistrationLifetimeDecorator>(registration); | ||
} | ||
|
||
[Fact] | ||
public void SingletonsRegisteredDirectlyAreWrappedWithLifetimeDecorator() | ||
{ | ||
var registry = new ScopeRestrictedRegistry(new object(), new Dictionary<string, object>()); | ||
|
||
registry.Register(ObjectRegistration); | ||
|
||
var typedService = new TypedService(typeof(object)); | ||
registry.TryGetRegistration(typedService, out IComponentRegistration registration); | ||
|
||
Assert.IsType<ComponentRegistrationLifetimeDecorator>(registration); | ||
} | ||
} | ||
} |