Ejemplo n.º 1
0
        public void DoesNotReturnSameInstanceTwice()
        {
            var injectionist = new Injection.Injectionist();

            injectionist.Register(c => new Something());

            injectionist.Decorate(c => c.Get <Something>());

            var result = injectionist.Get <Something>();

            Assert.That(result.TrackedInstances.OfType <Something>().Count(), Is.EqualTo(1));
        }
Ejemplo n.º 2
0
        public void CanGetResolvedInstancesOfSomeParticularType()
        {
            var injectionist = new Injection.Injectionist();

            injectionist.Decorate <IService>(c => new Decorator("2", c.Get <IService>()));
            injectionist.Decorate <IService>(c => new Decorator("3", c.Get <IService>()));
            injectionist.Decorate <IService>(c => new Decorator("4", c.Get <IService>()));

            injectionist.Register <IService>(c => new Primary("1"));

            var result = injectionist.Get <IService>();

            var instanceNames = result.TrackedInstances
                                .OfType <INamed>()
                                .Select(n => n.Name)
                                .ToList();

            Console.WriteLine($@"Instance names:

{string.Join(Environment.NewLine, instanceNames.Select(name => $"    {name}"))}");

            Assert.That(instanceNames, Is.EqualTo(new[] { "1", "2", "3", "4" }));
        }