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

Report existing interface registrations when ResolveUnregisteredConcreteTypes is false #781

Closed
dotnetjunkie opened this issue Dec 3, 2019 · 1 comment
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

@dotnetjunkie dotnetjunkie commented Dec 3, 2019

Simple Injector outputs pretty clear exceptions in case misregistrations are made. For instance in case a registration can't be found but other, similar registrations are available. When ResolveUnregisteredConcreteTypes is set to false, however, the message becomes less clear. With the coming #780 change, ResolveUnregisteredConcreteTypes will be false by default, which means it would be good to improve the message in that situation.

Example:

public interface IService { }
public class ServiceImpl : IService { }
public class Consumer { public Consumer(ServiceImpl service) { } }

static void Main(string[] args)
{
    var container = new Container();
    container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
    container.Options.ResolveUnregisteredConcreteTypes = false;

    container.Register<IService, ServiceImpl>(Lifestyle.Scoped);
    container.Register<Consumer>();

    container.Verify();
}

The exception thrown is the following:

The configuration is invalid. Creating the instance for type Consumer failed. The constructor of type Consumer contains the parameter with name 'service' and type ServiceImpl that is not registered. Please ensure ServiceImpl is registered, or change the constructor of Consumer. Note that the container's Options.ResolveUnregisteredConcreteTypes option is set to 'false'. This disallows the container to construct this unregistered concrete type.

The exception should note that there is a registration for IService that maps to ServiceImpl.

@dotnetjunkie dotnetjunkie added the feature label Dec 3, 2019
@dotnetjunkie dotnetjunkie added this to the v4.9 milestone Dec 3, 2019
@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Jan 5, 2020

feature-781 branch created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.