Skip to content

Decorated singleton causes recursive exception #67

Description

@ipjohnson

This should work so that you can wrap singletons with decorators.

        [Fact]
        public void Intercept_Singleton_Before_Lifestyle_Test()
        {
            var container = new DependencyInjectionContainer
            {
                c =>
                {
                    c.Export<Calculator>().As<ICalculator>().Lifestyle.Singleton();
                    c.Export<Interceptor>().Lifestyle.Singleton();
                    c.Intercept<ICalculator, Interceptor>();
                }
            };

            var calculator = container.Locate<ICalculator>();

            Assert.NotNull(calculator);

            var value = calculator.Add(2, 3);

            Assert.Equal(5, value);

            var interceptor = container.Locate<Interceptor>();

            Assert.NotNull(interceptor);
            Assert.NotNull(interceptor.Arguements);
            Assert.Equal(2, interceptor.Arguements.Length);
            Assert.Equal(2, interceptor.Arguements[0]);
            Assert.Equal(3, interceptor.Arguements[1]);
        }


This was mentioned in issue #66

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions