Skip to content

Conversation

@dahlbyk
Copy link
Collaborator

@dahlbyk dahlbyk commented Apr 6, 2025

Testing a Registry that uses Configure()/Register() (from #2) 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'

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

var container = new Container();
container.Configure(c =>
{
    c.IncludeRegistry<MyRegistry>();
    c.Populate([]);
});
container.AssertConfigurationIsValid();

Not terrible, just annoying.

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();
```
@dahlbyk
Copy link
Collaborator Author

dahlbyk commented Apr 6, 2025

I may have changed my mind already?

c.Populate([]) is annoying but c.Populate([], checkDuplicateCalls: true) is useful to make sure Populate() isn't used in the Registry or its dependencies. 🤔

@dahlbyk dahlbyk closed this Apr 6, 2025
@dahlbyk
Copy link
Collaborator Author

dahlbyk commented Apr 11, 2025

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 Populate(). Still wise for tests to call Populate([], checkDuplicateCalls: true) to guard against duplicates, but it seems safer to ensure that IServiceProvider and IServiceScopeFactory are available.

@dahlbyk dahlbyk reopened this Apr 11, 2025
@dustinsoftware dustinsoftware merged commit 75c6227 into dustinsoftware:main Apr 11, 2025
2 checks passed
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