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

Don't immediately throw in ConstructorInjectionConvention #181

Conversation

TheConstructor
Copy link
Contributor

rather let the ModelFactory throw as the convention is applied twice in hosting case.

It took me some time to discover why the unit-test of my pull-request #178 started failing. I immediately suspected #175, but it took me an hour to realize that the convention is immediately applied when added to the builder. Worse: in CommandLineService it is applied twice!

_application.Conventions
    .UseDefaultConventions() // this will apply ConstructorInjectionConvention and throw
    .UseConstructorInjection(serviceProvider); // this would work

By setting the ModelFactory to a throw-implementation we get to the second invocation were we set up the real deal. Effect for other apps is that the exceptions are a bit later, but also less nested. This also gives room for other conventions to set-up ModelFactories.

rather let the ModelFactory throw as the convention is applied twice in
hosting case
@TheConstructor TheConstructor force-pushed the fix/ConstructorInjectionConventionEarlyThorw branch from a80c375 to 88e8a45 Compare November 26, 2018 22:08
@TheConstructor
Copy link
Contributor Author

TheConstructor commented Nov 27, 2018

@natemcmaster I will probably only be able to fix the test after work. Was to keen on previewing #182 it seems :(

But it seems I manged to move the commit to be only included in #182.

@TheConstructor TheConstructor force-pushed the fix/ConstructorInjectionConventionEarlyThorw branch from e6357ab to 88e8a45 Compare November 27, 2018 06:55
This enables later conventions to supply ModelFactories for e.g.
interface-type-models
@TheConstructor
Copy link
Contributor Author

Everything should be ok now. Please @natemcmaster consider this pull-request. To be able to use constructor-injection with host-services after #175 either something like this is required or CommandLineService needs to be rewritten, so that UseConstructorInjection() is not called through UseDefaultConventions() or Application.AdditionalServices is initialized earlier.

@natemcmaster natemcmaster merged commit df0d28b into natemcmaster:master Nov 28, 2018
@natemcmaster
Copy link
Owner

Thanks for fixing this!

@TheConstructor
Copy link
Contributor Author

You're welcome! I am glad that we had/have a test!

@TheConstructor TheConstructor deleted the fix/ConstructorInjectionConventionEarlyThorw branch November 28, 2018 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants