Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeginLifetimeScope(object, Action<ContainerBuilder>) doesn't fail when using a duplicated tag #976

Closed
weelink opened this issue Apr 4, 2019 · 2 comments

Comments

@weelink
Copy link
Contributor

weelink commented Apr 4, 2019

There is inconsistent behaviour when beginning a new lifetime scope between LifetimeScope.BeginLifetimeScope(object) and LifetimeScope.BeginLifetimeScope(object, Action<ContainerBuilder>).

As indicated by the test NestedScopeTests.BeginLifetimeScopeCannotBeCalledWithDuplicateTag this will fail:

var rootScope = new ContainerBuilder().Build();
const string duplicateTagName = "ABC";
var taggedScope = rootScope.BeginLifetimeScope(duplicateTagName);
var differentTaggedScope = taggedScope.BeginLifetimeScope("DEF");

Assert.Throws<InvalidOperationException>(() => differentTaggedScope.BeginLifetimeScope(duplicateTagName));

If I use LifetimeScope.BeginLifetimeScope(object, Action<ContainerBuilder>) then this will not throw an exception:

var rootScope = new ContainerBuilder().Build();
const string duplicateTagName = "ABC";
var taggedScope = rootScope.BeginLifetimeScope(duplicateTagName);
var differentTaggedScope = taggedScope.BeginLifetimeScope("DEF");

Assert.Throws<InvalidOperationException>(() => differentTaggedScope.BeginLifetimeScope(duplicateTagName, builder => builder.RegisterType<object>()));
@weelink
Copy link
Contributor Author

weelink commented Apr 4, 2019

PR to fix this: #977

@tillig tillig closed this as completed in 309d45a Apr 4, 2019
tillig added a commit that referenced this issue Apr 4, 2019
…BeginningLifetimeScope

Fix #976 - Throw an exception if a lifetime scope is created with a duplicate tag
@alexmg
Copy link
Member

alexmg commented Apr 9, 2019

Thanks for the PR! The contribution is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants