Validate presence of constructor argument types when calling BuildServiceProvider #2348
Labels
Done
This issue has been fixed
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
Milestone
From @spartan563 on Thursday, March 24, 2016 6:35:45 AM
Background
When defining a service which accepts dependencies through its constructor, you expect that all required services are present in the container for its construction. One would expect that, failing this contract, an exception would be thrown when building the container.
Issue
At the moment, it is possible to register a service whose constructor requires services not present in the container. Building of the container (using BuildServiceProvider) succeeds and one will only encounter an error when you attempt to retrieve an instance of that service (or a service depending on it) through the
GetService
call.From an architectural perspective, this allows for certain edge cases to only be hit when the services are eventually requested at runtime, not necessarily at application start. Ideally, the application should fail to start should a condition like this be possible.
Reproduction
Suggestions
In an ideal world, this would be done as part of building up your call sites and within the call to BuildServiceProvider - throwing an exception if a dependency was not present in the container.
I understand this may not necessarily be possible, especially if you only build up the call sites when they are first required, in which case perhaps we can look at alternative solutions.
/cc @wesleyolis
Copied from original issue: aspnet/DependencyInjection#392
The text was updated successfully, but these errors were encountered: