-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Hello,
I have put together a couple of test cases to show this issue. I'm seeing some funny behaviour when attempting to use Microsoft.Extensions.Options;.
This first test case shows adding Options to a root level container, then resolving them, and it passes:
[Fact]
public void Options_Register_Root_Resolve_Root()
{
ServiceCollection services = new ServiceCollection();
services.AddOptions();
services.Configure<MyOptions>((a) =>
{
a.Prop = true;
});
StructureMap.Container container = new StructureMap.Container();
container.Populate(services);
IServiceProvider sp = container.GetInstance<IServiceProvider>();
IOptions<MyOptions> options = sp.GetRequiredService<IOptions<MyOptions>>();
Assert.True(options.Value?.Prop);
}
That's fine so far. The problem comes when I try and configure this at child container level.
Here is the failing test case:
[Fact]
public void Options_Register_Child_Resolve_Child()
{
ServiceCollection services = new ServiceCollection();
StructureMap.Container container = new StructureMap.Container();
container.Populate(services);
var childContainer = container.CreateChildContainer();
childContainer.Configure((a) =>
{
var childServices = new ServiceCollection();
childServices.AddOptions();
childServices.Configure<MyOptions>((b) =>
{
b.Prop = true;
});
a.Populate(childServices);
});
IServiceProvider sp = childContainer.GetInstance<IServiceProvider>();
IOptions<MyOptions> options = sp.GetRequiredService<IOptions<MyOptions>>();
Assert.True(options.Value?.Prop);
}
This latter test case, the delegate to configure the option b.Prop = true; is never called.
I'm not very advanced with structuremap, would appreciate any guidance etc.
Thanks
Metadata
Metadata
Assignees
Labels
No labels