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

Microsoft.Extensions.Options and child container - failing test case #43

Open
dazinator opened this issue Aug 19, 2018 · 5 comments
Open

Comments

@dazinator
Copy link

dazinator commented Aug 19, 2018

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

@dazinator dazinator changed the title Problem with Microsoft.Extensions.Options - failing test case Microsoft.Extensions.Options and child container - failing test case Aug 19, 2018
dazinator added a commit to dazinator/StructureMap.Microsoft.DependencyInjection that referenced this issue Aug 26, 2018
@dazinator
Copy link
Author

Any updates on this one?

@khellang
Copy link
Member

khellang commented Jan 6, 2019

I'm not really sure what to do about this one? I don't really know SM well enough to say what the issue might be or how to fix it.

@dazinator
Copy link
Author

dazinator commented Jan 6, 2019

That makes two of us ;-)
I found this issue: structuremap/structuremap#618 which looks very similar but I don't think it has really been resolved despite being closed.

@dazinator
Copy link
Author

It seems structuremap is no longer actively supported, and the replacement is Lamar: https://jasperfx.github.io/lamar/documentation/ioc/

I'll close this issue for now, i'll probably end up dropping support for structuremap completely, and tryijng out lamar at some point down the road.

@dazinator dazinator reopened this Jul 27, 2019
@dazinator
Copy link
Author

dazinator commented Jul 27, 2019

I can't use Lamar because Lamar doesnt support (or intend to support) child containers - which is something I'm dependent upon in order to model system wide, and per tenant wide services in a multitenant platform.

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

No branches or pull requests

2 participants