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

#43 - Added failing test case #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />

</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.DependencyInjection.Specification;
using Microsoft.Extensions.DependencyInjection.Specification.Fakes;
using Microsoft.Extensions.Options;
using Xunit;

namespace StructureMap.Microsoft.DependencyInjection.Tests
Expand Down Expand Up @@ -60,6 +61,33 @@ public void CanResolveIEnumerableWithDefaultConstructor()
Assert.NotEmpty(logger.Factory.Providers);
}

[Fact]
public void CanResolveIOptionsTFromChildContainer()
{

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);

}

private interface ILoggerProvider { }

private class TestLoggerProvider : ILoggerProvider { }
Expand Down Expand Up @@ -97,5 +125,10 @@ public Logger(ILoggerFactory factory)

public ILoggerFactory Factory { get; }
}

private class MyOptions
{
public bool Prop { get; internal set; }
}
}
}