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

Registering a mapping before a factory can cause an exception #52

Open
JSkimming opened this issue Jun 5, 2017 · 0 comments
Open

Registering a mapping before a factory can cause an exception #52

JSkimming opened this issue Jun 5, 2017 · 0 comments
Assignees
Labels

Comments

@JSkimming
Copy link
Owner

If a mapping from an interface to a concrete class comes before a factory mapping, then an exception will be thrown is the concrete class cannot be instantiated, e.g. it has multiple constructors.

This was discovered when mapping the Amazon S3 client to the interface, like this:

setup
    .Register<IAmazonS3, AmazonS3Client>()
    .RegisterFactory<AmazonS3Client>(CreateAmazonS3Client);

AmazonS3Client CreateAmazonS3Client()
{
    // Factory function implementation.
}

Since AmazonS3Client has multiple public constructors, the single constructor registration throw an exception when visited, but since it will be overridden, it should not throw an error.

If they the registrations are swapped, then no exception is thrown.

setup
    .RegisterFactory<AmazonS3Client>(CreateAmazonS3Client)
    .Register<IAmazonS3, AmazonS3Client>();
@JSkimming JSkimming self-assigned this Jun 5, 2017
@JSkimming JSkimming added the bug label Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant