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

Lifestyle mismatch diagnostic warning not thrown when applying multiple decorators #129

Closed
dotnetjunkie opened this issue Oct 1, 2015 · 0 comments
Assignees
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

Using the following definitions:

interface IHandler<T> { }
class IntHandler : IHandler<int> { }
class Decorator<T> : IHandler<T> {
    public Decorator(IHandler<T> decoratee) { }
}

The following code throws an 'lifestyle mismatch' exception:

var container = new Container();

container.Register(typeof(IHandler<int>), typeof(IntHandler), Lifestyle.Transient);
container.RegisterDecorator(typeof(IHandler<>), typeof(Decorator<>), Lifestyle.Singleton);

container.Verify();

And so does this code:

var container = new Container();

container.Register(typeof(IHandler<int>), typeof(IntHandler), Lifestyle.Transient);
container.RegisterDecorator(typeof(IHandler<>), typeof(Decorator<>), Lifestyle.Singleton);
container.RegisterDecorator(typeof(IHandler<>), typeof(Decorator<>), Lifestyle.Singleton);

container.Verify();

But the following code does not throw an exception:

var container = new Container();

container.Register(typeof(IHandler<int>), typeof(IntHandler), Lifestyle.Transient);
container.RegisterDecorator(typeof(IHandler<>), typeof(Decorator<>), Lifestyle.Singleton);
container.RegisterDecorator(typeof(IHandler<>), typeof(Decorator<>), Lifestyle.Singleton);
container.RegisterDecorator(typeof(IHandler<>), typeof(Decorator<>), Lifestyle.Singleton);

container.Verify();

When more than two decorators are wrapped around a type, everything deeper than the second decorator doesn't get validated anymore.

@dotnetjunkie dotnetjunkie self-assigned this Oct 1, 2015
@dotnetjunkie dotnetjunkie added this to the Simple Injector v3.1 milestone Oct 1, 2015
dotnetjunkie pushed a commit that referenced this issue Oct 4, 2015
@dotnetjunkie dotnetjunkie modified the milestones: Simple Injector v3.0.6, Simple Injector v3.1 Oct 4, 2015
dotnetjunkie pushed a commit that referenced this issue Oct 4, 2015
Registrations that where wrapped with three or more decorators didn't
get diagnosed. (fixes #129)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant