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

Instance Creation Issue with Property injection and lazy instantiation #718

Closed
blsmithers opened this issue Feb 15, 2016 · 3 comments
Closed
Labels

Comments

@blsmithers
Copy link

Hi, I stumbled on an issue and think it might be similar to the issue described in #666. The below is failing for me with the error message "An item with the same key has already been added.". I was hoping this case would be possible, any help you could give me would be appreciated!

static void Main(string[] args) {
            var builder = new ContainerBuilder();

            builder.RegisterType<A>().SingleInstance();
            builder.RegisterType<B>().SingleInstance().PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);

            using (var container = builder.Build())
            {
                var myA = container.Resolve<A>();
            }
        }

        public class A
        {
            public A(Lazy<B> b)
            {
                var myB = b.Value;
            }
        }

        public class B 
        {
            public A A { get; set; }
        }
@blsmithers blsmithers changed the title Instance Creation Issue with Property injection and factory delegates Instance Creation Issue with Property injection and lazy instantiation Feb 15, 2016
@tillig
Copy link
Member

tillig commented Feb 18, 2016

Verified. It does seem to be around the use of Lazy<T> since removing Lazy<T> and using T directly doesn't encounter this. We'll have to see if we can track this down. Thanks!

@tillig
Copy link
Member

tillig commented Aug 16, 2018

While the exception message is different now, this is still an issue. The issue is getting caught in LifetimeScope.GetOrCreateAndShare and it seems the use of Lazy<T> doesn't carry with it the circular property dependency information. I've added a failing unit test (skipped) to the solution.

Note we also have #798 where we're trying to figure out better circular dependency handling. The use of Lazy<T> needs to be considered there.

@tillig
Copy link
Member

tillig commented Sep 24, 2020

This appears to have been resolved with the overhaul to the internals in v6. The skipped/failing test for this issue can be marked to run and it now passes.

Fix will be released with v6.

tillig added a commit that referenced this issue Sep 24, 2020
@tillig tillig closed this as completed Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants