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

Contravariant singletons not working quite as expected #53

Closed
LordZoltan opened this Issue Sep 21, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@LordZoltan
Collaborator

LordZoltan commented Sep 21, 2017

Building on the contravariance examples (ordered enumerables example in the contravariance docs on rezolver.co.uk) - if you register a type as a singleton against a contravariant type, then I would expect only one instance to be created for requested type.

So:

container.RegisterSingleton(typeof(ShapeAreaComparer), typeof(IComparer<I2DShape>));

var a = container.Resolve<IComparer<Rectangle>>();
var b = container.Resolve<IComparer<Square>>();
var c = container.Resolve<IComparer<Circle>>();

// currently fails
Assert.Same(a, b);
Assert.Same(b, c);

Currently, Rezolver will create singletons, but one per unique requested type - i.e. IComparer<Square>, IComparer<Circle> get their own two separate instances.

Ideally, Rezolver should create one single instance for all these types.

The same should probably also be true if these were scoped.

@LordZoltan LordZoltan self-assigned this Sep 21, 2017

@LordZoltan LordZoltan added the bug label Sep 21, 2017

@LordZoltan

This comment has been minimized.

Collaborator

LordZoltan commented Sep 21, 2017

Note that the documentation referred to in this issue will only be public when package version 1.3 is released. Am currently working on this over in the dev branch.

@LordZoltan LordZoltan changed the title from Contravariant singletons not working quite as expected to Contravariant singletons not working quite as expected Oct 29, 2017

@LordZoltan LordZoltan added this to the 1.3.3 milestone May 15, 2018

@LordZoltan LordZoltan added the ready label May 15, 2018

LordZoltan added a commit that referenced this issue May 18, 2018

@LordZoltan LordZoltan closed this May 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment