Ensure container has IServiceProvider/IServiceScopeFactory#3
Merged
dustinsoftware merged 1 commit intodustinsoftware:mainfrom Apr 11, 2025
Merged
Ensure container has IServiceProvider/IServiceScopeFactory#3dustinsoftware merged 1 commit intodustinsoftware:mainfrom
IServiceProvider/IServiceScopeFactory#3dustinsoftware merged 1 commit intodustinsoftware:mainfrom
Conversation
Testing a Registry that uses Configure()/Register() should not depend on
calling Populate() for factory or scoped service descriptors to work.
> StructureMap.StructureMapConfigurationException:
> No default Instance is registered and cannot be automatically determined
> for type 'System.IServiceProvider'
Workaround:
```
var container = new Container();
container.Configure(c =>
{
c.IncludeRegistry<MyRegistry>();
c.Populate([]);
});
container.AssertConfigurationIsValid();
```
Collaborator
Author
|
I may have changed my mind already?
|
Collaborator
Author
|
I have unchanged my mind. We'll be using this infrastructure to migrate registries that are consumed by legacy apps that won't necessarily ever call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Testing a
Registrythat usesConfigure()/Register()(from #2) should not depend on callingPopulate()for factory or scoped service descriptors to work.This isn't a huge problem in tests, but as I noted below we plan to convert registries that are only used in legacy apps that might never call
Populate().Workaround
Not terrible, just annoying.