Example #1
0
        public void CreateOnlyOne()
        {
            Resolver.GetConfigurator().Bind <IBoundAttribTest>().To <BoundAttribTest>().SetSingletonScope().DisableOverride();
            ActivatorFactory.SetBoundActivator();
            var actual1 = ActivatorFactory.Activator.Activate <IBoundTest>(typeof(BoundTestOnlyOneInstance));
            var actual2 = ActivatorFactory.Activator.Activate <IBoundTest>(typeof(BoundTestOnlyOneInstance));

            Assert.AreSame(actual1.BoundAttribute, actual2.BoundAttribute);
            ActivatorFactory.ResetActivator();
        }
Example #2
0
        public void CreateFullyInitializedObject()
        {
            Resolver.GetConfigurator().Bind <IBoundAttribTest>().To <BoundAttribTest>();
            ActivatorFactory.SetBoundActivator();
            var activator = ActivatorFactory.Activator;
            var actual    = activator.Activate <IBoundTest>(typeof(BoundTest));

            Assert.IsNotNull(actual.BoundAttribute);
            Assert.IsNotNull(actual.TestGetter);
            Assert.IsInstanceOfType(actual.BoundAttribute, typeof(BoundAttribTest));
            Assert.IsInstanceOfType(actual.TestGetter, typeof(BoundAttribTestAnotherOne));
            var sameTwice = actual.TestGetter;

            //Run the whole thing once more to test cache and scope settings.
            activator = ActivatorFactory.Activator;
            actual    = activator.Activate <IBoundTest>(typeof(BoundTest));
            Assert.IsNotNull(actual.BoundAttribute);
            Assert.IsNotNull(actual.TestGetter);
            Assert.IsInstanceOfType(actual.BoundAttribute, typeof(BoundAttribTest));
            Assert.IsInstanceOfType(actual.TestGetter, typeof(BoundAttribTestAnotherOne));
            Assert.AreSame(sameTwice, actual.TestGetter);
            ActivatorFactory.ResetActivator();
        }