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

Add check to InstanceProducer constructor preventing incompatible Registration objects from being supplied #52

Closed
dotnetjunkie opened this issue May 22, 2015 · 0 comments
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

This code compiles and runs:

// class Logger : ILogger
var registration = Lifestyle.Transient.CreateRegistration<ILogger, Logger>(container);
// Logger does not implement IPlugin
var producer = new InstanceProducer(typeof(IPlugin), registration);
object instance = producer.GetInstance();

The returned instance is of type Logger. But this is about the only case where this works. When a decorator is applied to IPlugin, an ugly exception will be thrown when the expression tree is built. Obviously, casting the GetInstance() result to an IPlugin will fail.

A pre-condition check needs to be added to prevent that the InstanceProducer can't be created.

This can actually be a bit tricky, because some parts of the system create Registration instances without or with incorrect ImplementationTypes. Especially the decorator subsystem for uncontrolled collections does this.

@dotnetjunkie dotnetjunkie added this to the Simple Injector v3.0 milestone May 22, 2015
@dotnetjunkie dotnetjunkie removed this from the Simple Injector v3.0 milestone Jun 23, 2015
@dotnetjunkie dotnetjunkie added this to the Simple Injector v3.1 milestone Sep 7, 2015
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